Show excerpts if no "read more" in post? (3 posts)

  1. Matt Pusateri
    Posted 1 year ago #

    I'm currently working on a loop that is showing the content of post up to the "read more" spot. Looks like this:

    <p><?php the_content('Read more »'); ?></p>

    But what I'd like to be able to do is show the_excerpt instead if there is no "read more" inserted into a post... I've been searching around but can't seem to find the right way to use conditional/query code to deliver that...

    Any suggestions?

  2. Michael
    Part-Time Forum Moderator
    Posted 1 year ago #

    you could check the post's content for the string '<!--more-->';

    for example:
    <?php if( strpos( $post->post_content, '<!--more-->' ) === false ) { the_excerpt(); } else { the_content('Read more »'); } ?>


  3. Matt Pusateri
    Posted 1 year ago #

    Wow. That worked... Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic