david.brunelle
Member
Posted 2 years ago #
I've been trying to figure out how I can check for the existence of the "more" quick tag in a post. This is the scenario:
- If the author has used the "more" quick tag, then treat the post normally.
- if the author didn't use the "more" tag, then only show an excerpt
In code terms:
<?php
if($more_link) {
the_content();
}
else {
the_excerpt();
}
?>
Any ideas?
<?php
if(strpos(get_the_content(),'more-link') === false) {
the_excerpt();
}
else {
the_content();
}
?>
How about:
<?php
if( strpos( $post->post_content, '<!--more-->' ) ) {
the_content();
}
else {
the_excerpt();
}
?>
david.brunelle
Member
Posted 2 years ago #
Thanks alchymyth & esmi. Here's what I came up with (around the same time you both replied):
<?php
if(preg_match('/<!--more(.*?)?-->/', $post->post_content)) {
the_content();
}
else {
the_excerpt();
}
?>
I think you'll find that strpos() is more efficient/faster and has less CPU impact than preg_match().