• Resolved harveypooka

    (@harveypooka)


    Evening all,

    I need a way to display a list of subcategories of a category. Like this:

    “Please click a country for a list of our current projects:

    ? Africa
    ? Sri Lanka”

    With Projects (parent) and Africa and Sri Lanka being subcategories (children).

    When the user clicks on Projects, I’d like a list of the subcategories to appear, instead of the default list of posts in all of the categories.

    I’ve managed to make the page display the categories of the posts (5 Africa’s and 2 Sri Lanka’s due to the amount of posts), but I can’t seem to find anything that’ll let me display the children of a parent as a list.

    I’m guessing I can do this by using get_the_category_list() or the_category() and utilising some arcane argument/parameter, but I’m at a loss.

    Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You and me are in the same boat it seems, there doesn’t seem to be much of anyone to explain this as I can see.
    It’s pretty sad as a basic need for navigating content. Any plugins I’ve found just cause more problems than anything.

    Please someone, put this in a Ultra-For-Dummies-Explanation if you can.

    I’m about to look for another content solution…

    Thread Starter harveypooka

    (@harveypooka)

    I’m going to keep looking on the forums and brush up on some PHP tomorrow. There will be a way to do it, but it may involve some PHP hacking.

    Once I’ve found the solution I’ll be happy to help you. I don’t want to give up on WordPress as it’s a bloody marvelous endeavor.

    Thread Starter harveypooka

    (@harveypooka)

    Well, I’ve taken a look around at multiple loops, a variety of plugins and even some PHP-ness, but I can’t find anything.

    As this is for a charity website and I have no experience in PHP or time to learn it right now, I think I’ll have to find another content solution too.

    Damn.

    Thread Starter harveypooka

    (@harveypooka)

    Right. I’m cheating.

    Instead of having a generated list I’m simply making it manual. I’ll look into creating it from the database another time.

    I’m removing the loop and any tags and manually placing absolute links to my subcategories/children.

    Cheating, but it’ll work for the time being!

    You can use the following codes.

    $cat = 5;
    wp_list_categories("orderby=name&show_count=1
    &use_desc_for_title=0&hide_empty=0&child_of=$cat&title_li");

    And you can get a widget about Cats of Cats by this link. But language of the site is Turkish. If you want to download the widget, you can click the link in this sentence “Bile?eni buradan indirin”
    Usage the widget: Download/Upload to the plugin directory/Activate the widget and costumize your widget
    I’m sorry for my poor English.

    I have successfully displayed children of categories on my WordPress blog by using a work-around in which I named the categories hierarchically.

    In the situation that harveypooka described, the categories would become Projects > Africa and Projects > Sri Lanka.

    Thread Starter harveypooka

    (@harveypooka)

    Thank you so much, Yakuphan and Ellen.

    I’ll give both of these a shot tomorrow and see if they solve my problem.

    Yakuphan – where did you find your code, or information about it? The Codex seemed a little thing on information. Oh, and your English is 100 times better than my Turkish! ??

    Hi, again.
    If you download this widget, you can show post count and see wp_list_categories function on work.

    I found my codes in this widget from this link.
    “Only Show Children of a Category” title gives the information.
    But if you want to know about “get_category_children()” function, i can’t remember. Maybe this link help you. I take the child categories like “1 2 4 5”, and i explode it. Of course i use a “for each”.

    $childs = get_category_children($cat, $before = ' ', $after = '');
    $catts = explode (' ', trim($childs));
    foreach($catts as $catt) {
    $catname = get_cat_name($catt);
    echo '

    • '.$catname.'
    • ';
      }

      You can use the following codes in this widget.

      $cat = (int) $cat;
      //$cat is category id
      wp_list_categories("orderby=name&show_count=1
      &use_desc_for_title=0&hide_empty=0&child_of=$cat&title_li");

      These codes are very simple and use the WP API. Important keyword is child_of. You can costumize that code as you want.

    Very simple solution, no hacks or widgets.

    Add this code to wherever you want it (but customize the child_of=3 to your parent category)

    <?php wp_list_cats(‘sort_column=id&optioncount=0&use_desc_for_title=0&child_of=3’); ?>

    Heres an explanation of what it does:

    “<?php wp_list_cats(‘sort_column=id” = list categories
    “&optioncount=0” = don’t include the count of articles
    “&use_desc_for_title=0” = sort by title descending
    “&child_of=3′); ?>” = all categories under the parent category 3

    Hope this help you all
    Renegade

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to display children of a category’ is closed to new replies.