Created
March 29, 2018 12:56
-
-
Save nixonmedia/df1fbfd60a02b82c352a6048f3781e70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showBeforeMore($fullText){ | |
$more = '<!--more-->'; | |
if(strpos($fullText, $more)!==false){ | |
$morePos = strpos($fullText, $more); | |
$rest = str_replace($more, '', $morePos); | |
//only show the text before the <!--more--> | |
print substr($fullText,0,$morePos); | |
//add a Read More anchor | |
print '<a href="#" class="read_more">Continue Reading <i class="far fa-angle-down"></i></a>'; | |
//wrap the rest of the content after the <!--more--> in a hidden class | |
echo '<div class="hide_content">'; | |
$index = strpos($fullText, $more) + strlen($more); | |
echo substr($fullText, $index); | |
echo '</div><!--/hide-->'; | |
} else { | |
print $fullText; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment