Forums

[resolved] Checking if category has posts (5 posts)

  1. newkind
    Member
    Posted 3 years ago #

    Hi,

    I would like to do such thing :

    I've got a table which displays posts from category 'test'. Posts are displayed using standard

    <?php query_posts('category_name=test&amp;showposts=3'); ?>
     <?php while (have_posts()) : the_post(); ?>

    But i'd like to add another loop above this loop (and above the wrapper that this loop is inside of) so it would check if the category 'test' has posts - if so go and do the loop mentioned above, if not - display nothing. Or maybe there is another way to hide a theme module ?

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    $test=get_posts('category_name=test');
    if ($test) {
    //found posts
    }

  3. newkind
    Member
    Posted 3 years ago #

    thank you :)

  4. johnnyriss
    Member
    Posted 2 years ago #

    awesome. thx much

  5. Brendino
    Member
    Posted 2 years ago #

    This helped me!

    Thanks, MichaelH :D

Topic Closed

This topic has been closed to new replies.

About this Topic