Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a main page that consists of 7 categories being output by wp_list_categories, each li specifically includes one ID. These categories are directed to a category-page.php specifically built for each category. Now, each category has sub categories. So on each of the category pages, I want to build out custom queries for each sub category. Example: the Weightloss category on the main page, links to the category-weightloss.php page. Within Weightloss, there are six sub categories. What is the best way, to create six different queries, in seperate div's, so I can style them? I have looked over WP_Query, but I am not sure of the best, and most appropriate, way to do this.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I figured this out on my own. I use the code below and duplicated it as many times as I needed without any issues so far. If anyone thinks this is incorrect than please comment. I was not using the main loop anywhere else on this page and used WP_Query.

<ul class="subcats-list">
<?php
$weightloss = new WP_Query();
$weightloss->query('showposts=5');

while ($weightloss->have_posts()) : $weightloss->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>

 </ul><!-- subcat -->
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.