getfluid
3/9/2018 - 7:49 PM

Custom Read More Tag Functionality

Functionality to truncate the WYSIWYG where the Read More Tag is used.

/**
 * Custom read more functionality
 * for the WYSIWYG Read More Tag
 */

function readmore($fullText){
	if(@strpos($fullText, '<!--more-->')){
		$morePos  = strpos($fullText, '<!--more-->');
		$fullText = preg_replace('/<!--(.|\s)*?-->/', '', $fullText);
		echo substr($fullText,0,$morePos);
    echo "<div class=\"read-more-content\">". substr($fullText,$morePos,-1) . "</div>";
    echo "<div class=\"read-more\"><a><span>Read More</span><span class=\"hide\">Read Less</span></a></div>";
	} else {
		echo $fullText;
	}
}
$('.read-more a').on('click', function(event) {
  event.preventDefault();
  $('span', this).toggleClass('hide');
  $(this).parent().prev().slideToggle();
});