How to check if three different categories have posts and act upon each of them
-
Clumsy title, but here is what I mean. And I really hope someone will read all this 😉
I have three top level categories, ie Subject, Countries, Regions. Each post is asigned to three categories, each being one of the subcategories of those top level categories, ie Animals, France, Region 12. But now I have to populate some lists so I can create maps with CSS for my navigation. In the end people will see a page with animals inside France inside region 12.
The first level is easy and on index.php:
$subjects = get_categories('hide_empty=0&child_of=2'); foreach($subjects as $subject) { $test = get_posts('category='.$subject->cat_ID); if($test) { echo "<li><a href=\"" . get_category_link($subject->cat_ID) . "\"><span>". get_cat_name($subject->cat_ID) ."</span></a></li>"; } else { echo "<li class=\"maincatinactive\"><span>". get_cat_name($subject->cat_ID) ."</span></li>"; } }
But I’m really stuck on the second and third part of my navigation. When I’m on the category.php page I first want to show the countries that have posts AND are inside the previously chosen subcategory Animals. And after clicking on a country I want to create a map of the chosen country with regions and show only the regions in color that have posts AND are inside category France AND inside category Animals. And I have no idea how to accomplish that. I need some way to check at each reloading of the category.php page if that subcat has posts AND belongs to one of the other categories.
Any ideas on how to do this?
- The topic ‘How to check if three different categories have posts and act upon each of them’ is closed to new replies.