WordPress.org

Support

Support » Themes and Templates » How to Detect If the “optional excerpt” is empty or not?

How to Detect If the “optional excerpt” is empty or not?

  • If “optional excerpt” has typed something, show the_excerpt. (don’t show the_content()), otherwise show the_content();

    Is that doable?

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    if( $post->post_excerpt ) {
        the_excerpt();
    } else {
        the_content();
    }
    ?>

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Detect If the “optional excerpt” is empty or not?’ is closed to new replies.
Skip to toolbar