Excerpt if there is no more tag? (5 posts)

  1. Alan Smithee
    Posted 6 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().

  2. Alan Smithee
    Posted 6 years ago #

    Something like this (for illustration only):

    <?php if ($more) : ?>
    <?php the_content(); ?>
    <?php else : ?>
    <?php the_excerpt(); ?>
    <?php endif; ?>
  3. Mark / t31os

    Posted 6 years ago #

    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.

  4. Ryan
    Posted 6 years ago #

    @t31os_: Has anyone told you today that you're fantastic? Well you are. Thx m8.

  5. Mark / t31os

    Posted 6 years ago #

    It's comments like these that make my time spent here all worth it, thanks mate... ;)

Topic Closed

This topic has been closed to new replies.

About this Topic