• This has been driving me crazy for over a day now, hoping someone can help.

    Scenario: I have a category established “portfolio”, and then 4 sub-categories as children of this.

    I have multiple posts with the “portfolio” category checked, as well as the subcategory checked (type of work).

    I have a custom page template where I am pulling all “posts” from the parent category and displaying them. Everything works fine. What I need to do is pull the “subcategory” name as well for each post so I can display it in the HTML. For instance, one subcategory might be “web design”. On that particular post, the parent category “portfolio” is checked, as well as “web design”. I need to somehow grab the name of the subcategory and display it.

    I’ve tried numerous things, and one worked at first (forget what code I used) where it was pulling the 2nd value of the category array. The problem is WP lists them alphabetically so it didn’t work for all categories.

    I’ve tried messing with ‘child_of=3’ where 3 is the parent category name, but I simply can’t find the right wording to get it working. Any ideas?

Viewing 1 replies (of 1 total)
  • Hi,

    [sourcecode language="php"]
    if (is_category()) {
    $this_category = get_category($cat);
    if (get_category_children($this_category->cat_ID) != “”) {
    echo “
    Subcategories

    “;
    echo “

    “;
    wp_list_categories(‘orderby=id&show_count=0&title_li=
    &use_desc_for_title=1&child_of=’.$this_category->cat_ID);
    echo “

    “;
    }
    }
    [/sourcecode]

    Thanks,

    Shane G.

Viewing 1 replies (of 1 total)
  • The topic ‘Return the name of the subcategory?’ is closed to new replies.