Alan Smithee
Member
Posted 2 years ago #
Is there a way to show an excerpt if there is no "more tag?"
I just changed from a magazine style layout to a more traditional blog style home page. I want to show html excerpts using the "more" tag the_content() for all new posts, but don't want to go back and edit 700 posts. For the older ones I want to use the plain text the_excerpt().
Alan Smithee
Member
Posted 2 years ago #
Something like this (for illustration only):
<?php if ($more) : ?>
<?php the_content(); ?>
<?php else : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
Use inside the loop (of course).
<?php
// Check the content for the more text
$ismore = @strpos( $post->post_content, '<!--more-->');
// If there's a match
if($ismore) : the_content();
// Else no more tag exists
else : the_excerpt();
// End if more
endif;
?>
Tested as working. There are known bugs with strpos under certain PHP versions, but it should not effect the above code, i've surpressed errors for the above with the @, so in the event any error does occur you won't get the error output onscreen.
DaoByDesign
Member
Posted 2 years ago #
@t31os_: Has anyone told you today that you're fantastic? Well you are. Thx m8.
It's comments like these that make my time spent here all worth it, thanks mate... ;)