Support » Themes and Templates » Hide loop if less then X in category…

  • I’m using a custom page as my startpage (it’s a one-page website), wisch is populated with posts from different categories.

    Now, I have this loop:

    <div class="block">
    <ol class="list-text archive">
    
    	<?php $recent = new WP_Query(); ?>
    	<?php $recent->query('cat=3&showposts=100&offset=3'); ?>
    	<?php while($recent->have_posts()) : $recent->the_post(); ?>
    
    	        <li>
    	         <h3><?php the_title(); ?></h3>
    	       	 <?php the_content(); ?>
    		</li>
    
    	<?php endwhile; ?>
    
    </ol>
    
      <div class="addon">
        <a class="toggle" href="#">More shows</a>
      </div>
    
    </div>

    What I want to do is to hide the whole block if the there is less than 3 posts from this category. Been googling for hours, can’t figure out how to do it!

Viewing 1 replies (of 1 total)
  • $found_posts
    The total number of posts found matching the current query parameters.
    WP_Query

    that should do the trick for you.

    $recent->found_post something like that then compare the value and depending on result show it or not.

Viewing 1 replies (of 1 total)
  • The topic ‘Hide loop if less then X in category…’ is closed to new replies.