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.

The code below is based on a couple of forum posts from a couple of places. To a certain extent, it works. The issue I am having is that it only shows "Activities", no matter what parent category I'm in. I tried replacing "activities" with a number of very unsuccessful alternatives (conditionals, get functions, and others); nothing worked.

<?php $cat = 'Activities'; /* This is the problem area.
   Trying to get $cat to equal the name of the selected parent categories; the rest of
   the code seems to be working, at least for the Activities category. */

$catID = get_cat_ID($cat);
echo '<h2>' . $cat . '<h2>';
$subcats = get_categories('child_of=' . $catID);
foreach($subcats as $subcat)
{
    echo '<h4>' . $subcat->cat_name . ' </h4>';
    echo '<ul>';
    $subcat_posts = get_posts('cat=' . $subcat->cat_ID);
    foreach($subcat_posts as $subcat_post)
    {
        echo '<li>';
        $postID = $subcat_post->ID;
        echo '<a href="' . get_permalink($postID) . '">';
        echo get_the_title($postID);
        echo '</a>';
        echo '</li>';
    }
    echo '</ul>';
}?>
share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

If you are in a category context this should work and and you'll get the correct catID to work with.

function getCurrentCatID(){
    global $wp_query;
    if(is_category()){
        $cat_ID = get_query_var('cat');
    }
    return $cat_ID;
}
$catID = getCurrentCatID();
share|improve this answer
    
thanks for your reply... got it all working now... –  Michael Mar 5 '12 at 7:56
add comment

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.