Support » Everything else WordPress » Display Childcategories in dif cats

  • eversuns



    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?


Viewing 1 replies (of 1 total)
  • 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:

    We can steal from it to do this:

    $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.