If you have no interest in wordpress whatsoever, i’m sorry to announce that i’ll be wordpressing a lot in the next few weeks, so you might want to consider unsubscribing from this – otherwise excellent – website’s RSS feed. Sorry to see you go.

If on the contrary you dig WordPress like it’s your daddy’s car, you might be interested by this cute function i came up with, in need of a way to display a menu made of the present node (page, post or custom type) ‘s category children categories. Say that ten times aloud really fast to your neighbour, she’ll appreciate your geekiness, and if you’re in India, even find it sexy.

It works sidewide as long as each post is in at least one category.


function children_category_menu() {
    if (is_category() && !is_front_page()) {
        global $post;
        $categories = get_the_category($post->ID);
        if (is_array($categories) && count($categories) > 0) {
            $the_cat = 0;
            foreach ($categories as $c) {
                if ($c->category_parent == 0) {
                    $the_cat = $c;
                    break;
                }
            }
            /* --- Get the Children --- */
            if (get_category_children($the_cat->term_id) != "") {
                $class = $the_cat->category_nicename;
                echo '<ul id="current_subcategory_menu" class="category_top_menu ' . $class . ' clearfix">';
                pxln_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of=' . $the_cat->term_id);
                echo "</ul>";
            }
        }
    }
}

Put it in your theme’s functions.php then use it wherever you want this menu to appear by calling the function

 children_category_menu();