Created
March 14, 2014 21:36
-
-
Save mattbrett/9557507 to your computer and use it in GitHub Desktop.
Works, but always adds more button, even if there's only one paragraph.
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
<?php | |
function the_content_readmore($more_link_text = null, $stripteaser = 0) { | |
$content = get_the_content($more_link_text, $stripteaser); | |
$content = apply_filters('the_content', $content); | |
$content = explode("</p>", $content); | |
foreach ($content as $key => $value){ | |
if ($value != null || $value != ''){ | |
if ( !stripos( $content[$key], '<iframe' ) === false ){ | |
echo $content[$key]; | |
for($i = $key+1; $i < count($content); $i++ ){ | |
echo $content[$i]; | |
if ($content[$i] != null || $content[$i] != '') break; | |
} | |
} | |
else{ | |
for($i = $key; $i < count($content); $i++ ){ | |
echo $content[$i]; | |
if ($content[$i] != null || $content[$i] != '') break; | |
} | |
} | |
break; | |
} | |
else echo $value; | |
} | |
echo '<a href="javascript:void(0);" class="button button-more">Read More <i class="fa fa-lg fa-chevron-circle-down"></i></a>'; | |
} |
Line 8. Do you intend to say "There is no iframe" OR "Doesn't start with an iframe" ?
Total rewrite but this should do what you want: https://gist.github.com/kerihenare/9557715
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function creates a custom excerpt and tacks a "more" button on the end. The excerpt is limited to a single paragraph, or an iframe (embedded video) and a paragraph. The problem, is that the "more" button is shown at all times, even if only one paragraph exists.