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.

When viewing a parent category page, I am trying to list its sub-categories with each post title (max 5) underneath. I have managed to put together a code that lists sub category titles and I have managed to put together a separate code that is listing the categories with the post titles underneath. The problem with the last code is that it is only listing level 1 categories.

I have tried manually adding "parent" arguments or a "category slug" argument but neither has worked. Here is that code, how can I alter it so that it only displays the sub-categories of the current page instead of level 1 categories. This is all sitting inside the category.php template.

<!-- Category Archive Start -->
<ul class="catArchive">
$catQuery = $wpdb->get_results("SELECT * FROM $wpdb->terms AS wterms INNER JOIN $wpdb->term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id ) WHERE wtaxonomy.taxonomy = 'category' AND wtaxonomy.parent = 0 AND wtaxonomy.count > 0");

$catCounter = 0;

foreach ($catQuery as $category) {


    $catStyle = '';
    if (is_int($catCounter / 2)) $catStyle = ' class="catAlt"';

    $catLink = get_category_link($category->term_id);

    echo '<li'.$catStyle.'><h3><a href="'.$catLink.'" title="'.$category->name.'">'.$category->name.'</a></h3>';
        echo '<ul>';


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

            <li><a href="<?php echo $catLink; ?>" title="<?php echo $category->name; ?>">More <strong><?php echo $category->name; ?></strong></a></li>
    <?php } ?>
<!-- Category Archive End -->

Here is the code I used that displays all sub-category names without any respective post titles underneath:

<?php if(is_category( array( 35,36 ) ) ) { ?>

<div class="subcategories">


    if (is_category()) {
    $this_category = get_category($cat);
    $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category->category_parent."&echo=0"); else
    $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category->cat_ID."&echo=0");
    if ($this_category) { ?>

    <?php echo $this_category; ?>
    <?php } ?>


    <?php } ?>
share|improve this question
By 'parent category page' do you mean the top-level categories only? –  dalbaeb May 26 '13 at 14:09
add comment

Your Answer


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

Browse other questions tagged or ask your own question.