Support » Fixing WordPress » How can I avoid displaying empty the_content()?

  • I have a page.

    One of the default attributes of the page, is the ‘Page’ window where u enter your blog text.

    To display the content, I use the the_content() function in the follwoing code:

    if (have_posts()): while (have_posts()): the_post();
       echo '<div class="ui-tabs-panel">';
       the_content(); '<br />';
       echo '</div>';
    endwhile; endif;

    Question: How can I avoid displaying an empty ‘ui-tabs-panel’ if there is no test in the ‘Page’ attribute (empty content) ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Ups, spelling mistake.
    It should be ‘if there is no text’


    i don’t have anywhere to test this at the moment but you might do this.
    if (have_posts()): while (have_posts()): the_post();
    //whatever you want to be there if there is no content
    echo(‘<div class=”ui-tabs-panel”>’);
    the_content(); ‘
    endwhile; endif;

    Thanks jrm213, but that didn’t work 🙁

    I tried looking in Function Reference to see if there is anything there I can use. But didn\t find anything.

    Where can I see what properties ‘post’ has?

    Anyone got any suggestions for this?

    I was looking for the answer to this too. You were on the right track but missing a word.

    It should be $post->post_content like this:

    <?php if($post->post_content=="") : ?>
    <!-- Do stuff with empty posts (or leave blank to skip empty posts) -->
    <?php else : ?>
    <!-- Do stuff to posts with content -->
    <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How can I avoid displaying empty the_content()?’ is closed to new replies.