WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Alan Smithee
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

    Something like this (for illustration only):

    <?php if ($more) : ?>
    <?php the_content(); ?>
    <?php else : ?>
    <?php the_excerpt(); ?>
    <?php endif; ?>
  3. Mark / t31os
    Moderator
    Posted 4 years ago #

    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.

  4. Ryan
    Member
    Posted 4 years ago #

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

  5. Mark / t31os
    Moderator
    Posted 4 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

Tags