WordPress.org

Ready to get started?Download WordPress

Forums

How can I avoid displaying empty the_content()? (6 posts)

  1. spstieng
    Member
    Posted 6 years ago #

    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) ?

  2. spstieng
    Member
    Posted 6 years ago #

    Ups, spelling mistake.
    It should be 'if there is no text'

  3. jrm213
    Member
    Posted 6 years ago #

    hi,

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

  4. spstieng
    Member
    Posted 6 years ago #

    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?

  5. spstieng
    Member
    Posted 6 years ago #

    Anyone got any suggestions for this?

  6. MartyThornley
    Member
    Posted 5 years ago #

    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; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic