Support » Fixing WordPress » Excerpt if there is no more tag?

  • 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().

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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).

    // 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

    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.



    @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… 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Excerpt if there is no more tag?’ is closed to new replies.