Conditional Tag not working (must show text if no posts)
-
I’ve seen questioning posts like this before and not all are resolved, but I’ll take a crack at asking!
I would like certain text (or eventually certain html) to show when there are no posts in a category. This will eventually be for listing products, and if there are no products, a greyed out icon will show.
Anyway, this is the code I have now and I’m at a loss as to why it won’t work (though I’m more of a designer than php guru). If anything looks out of the ordinary, realize I’m using the “magic fields” plugin.
The Code:
<?php $my_query = new WP_Query(‘category_name=product-category’); ?>
<?php if (have_posts()) : ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div>
See this if there are posts in the category
</div><?php endwhile; ?>
<?php else : ?>
<p>See this if there are no posts in the category</p>
<?php endif; ?>———————-
To me the above is logical and should work. It DOES show text if there is a post in the category and the text DOES disappear if there are no posts, I just can’t get the “no post stuff” to appear when there are no posts!
Thanks in advance!
- The topic ‘Conditional Tag not working (must show text if no posts)’ is closed to new replies.