I have a problem with my first wordpress website. So far I’ve managed to sort any problem out, but for this one I need help from you, experienced wp users.
Well, below is a html block of my index.php file. What I need is an if statement to show the all the <div id=”news”> if there is at least one post in the news category. In other words, if the category news does not have any post, the <div id=”news”> should not be visible.
<div id="news" class="section_white_bg clearfix news_excerpt"> <h3 class="white_gradient_bg_heading">News</h3> <div class="white_gradient_bg_body clearfix"> <ul class="news_lines"> <?php if ($port = new WP_Query( array( 'post_type' => 'News', 'posts_per_page' => 3 ) ); while ( $port->have_posts() ) : $port->the_post(); ?> <li> <a href="<?php the_permalink(); ?>" class="border_button"> <h3 class="news_title"> <?php the_title(); ?> </h3> <br /> <?php the_excerpt(); ?> </a> </li> <?php endwhile; ?> </ul> </div> </div>
Hope you can help me. This is driving me mad. I’m using Types for custom post types.
- The topic ‘Make a block disappear if there are no posts in a category’ is closed to new replies.