WordPress.org

Ready to get started?Download WordPress

Forums

Hide loop if less then X in category... (2 posts)

  1. batrikperg
    Member
    Posted 1 year ago #

    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!

  2. LastForOne
    Member
    Posted 1 year ago #

    $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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.