WordPress.org

Ready to get started?Download WordPress

Forums

How to Detect If the "optional excerpt" is empty or not? (3 posts)

  1. marclin
    Member
    Posted 6 years ago #

    If "optional excerpt" has typed something, show the_excerpt. (don't show the_content()), otherwise show the_content();

    Is that doable?

  2. Kafkaesqui

    Posted 6 years ago #

    <?php
    if( $post->post_excerpt ) {
        the_excerpt();
    } else {
        the_content();
    }
    ?>
  3. mores
    Member
    Posted 6 years ago #

    Thanks Kafkaesqui ... that helped me with another issue. I wanted to use the permalink only if a post actually contained content ... otherwise just write the title.

    <ul>
    <?php global $post;
    $myposts = get_posts('numberposts=20&'."category=$category->id");
    foreach($myposts as $post) : setup_postdata($post);
    	if( $post->post_content ) { ?>
    		<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span class="datetime">(<?php the_time('j. F Y'); ?>)</span></li>
    	<?php } else { ?>
    		<li><?php the_title(); ?> <span class="datetime">(<?php the_time('j. F Y'); ?>)</span></li>
    	<?php } ?>
    <?php endforeach; ?>
    </ul>

    I'm posting it here just in case someone else is looking for something similar.

Topic Closed

This topic has been closed to new replies.

About this Topic