WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] If the_excerpt() is blank? (3 posts)

  1. twofivethreetwo
    Member
    Posted 5 years ago #

    I am using the_content() and the_excerpt() on my index page. Its a resource site where we link to others. With the_content() (and more) we have our text and then we use the_excerpt() to quote the site we are linking to. The problem arises when we post our own articles. We have no need for the_excerpt() and need to not display it if we left it blank. However doing a simple if (the_excerpt()) doesn't work since wordpress just uses content for it.

    Is there another way to do this? Since I have the_excerpt() wrapped with blockquote, is there a way to wrap the whole thing in an if statement?

  2. twofivethreetwo
    Member
    Posted 5 years ago #

    Was able to figure it out after some more browsing... For those interested in the same here is what mine looks like:

    <?php if (!get_the_excerpt()) { ?>
      <!-- show nothing if no ex
    <?php } else { ?>
     <blockquote>
      <?php the_excerpt(); ?>
     </blockquote>
    <?php } ?>

    Somebody else might have a better way to do this, but this works for me right now.

  3. Rian Rietveld
    Member
    Posted 4 years ago #

    Found this useful from
    http://wpcult.com/display-the_excerpt-only-if-there-is-text/

    if ( !empty( $post->post_excerpt ) ) :
    	the_excerpt();
    else :
    	false;
    endif;

Topic Closed

This topic has been closed to new replies.

About this Topic