WordPress.org

Support

Support » Miscellaneous » Display Childcategories in dif cats

Display Childcategories in dif cats

  • Hey,

    Im using this code

    <ul> <?php
     $cats = get_the_category($ID); wp_list_categories('child_of=$cats&title_li=&hide_empty=0'); ?></ul>

    And i would hope when i go to a category page it would display all the subcategories…. Why isnt it working?

    THanks

Viewing 1 replies (of 1 total)
  • Kafkaesqui
    Member

    @kafkaesqui

    1. Where is $ID assigned?

    2. get_the_category() returns an array of the category (or categories) a post (assumedly $ID) is under, whereas the ‘child_of’ parameter merely accepts a category ID #.

    I have a slightly in-depth code bit here:

    http://wordpress.org/support/topic/112666#post-659757

    We can steal from it to do this:

    <ul><?php
    $category = $wp_query->get_queried_object();
    $parent = ($category->category_parent) ? $category->category_parent : $category->cat_ID;
    wp_list_categories("child_of=$parent&title_li=&hide_empty=0"); ?></ul>

Viewing 1 replies (of 1 total)
  • The topic ‘Display Childcategories in dif cats’ is closed to new replies.