WordPress.org

Ready to get started?Download WordPress

Forums

Display Childcategories in dif cats (2 posts)

  1. eversuns
    Member
    Posted 6 years ago #

    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

  2. Kafkaesqui

    Posted 6 years ago #

    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>

Topic Closed

This topic has been closed to new replies.

About this Topic