WordPress.org

Ready to get started?Download WordPress

Forums

List hierarcichal categories with description? (7 posts)

  1. Xoda
    Member
    Posted 5 years ago #

    I want to make a page which lists categories with descriptions. I want them to show indented subcategories.

    No, I can't use wp_list_categories becuase for some €%&€ reason they can't show descriptions.

    No, I can't use get_categories because the hierarchical parameter doesn't work.

    So please don't just redirect me to those pages in the codex because they don't help.

    I've thought about using several get_categories and foreach, but for some @#-€& reason theres no working way to get only the top level, parent categories. Guess nobody though about that when the child_of-paramater was created?

    The only way I can think of now is getting a list with wp_list_categories('echo=0') and then use some kind of regular expression to get the id or slug, then use a foreach and get_categories('child_of=$x'). But should it really be that ridicolous hard to get a useful list of categories and subcategories, all with description?

    I have searched the forum but similar questions seems to gone unanswered or had solutions not appliable to my problem.

  2. tugbucket
    Member
    Posted 5 years ago #

    Link: Grab the Description on display in a list. See if that can help at all. I haven't done anything with subcategories but it's a start.

  3. Xoda
    Member
    Posted 5 years ago #

    I solved it by making a foreach-loop with get_categories, checking if it's a parent, then looping again with child_of

    It works but it has a disadvantage that the child-categories gets fetched two times.

  4. Xoda
    Member
    Posted 5 years ago #

    Working quite well actually, if you want to have look (the whole theme is not finished yet and there's not much content but you see the idea) http://www.photositescenter.com

  5. csbartus
    Member
    Posted 5 years ago #

    my bad thoughts removed ... :D

  6. csbartus
    Member
    Posted 5 years ago #

    $products = get_categories('child_of=5&hide_empty=0');
        foreach ( $products as $product ) {
          echo $product->cat_name . '->' . $product->cat_ID . '->' . $product->description . ' ';
        } ?>
  7. Joshuwar
    Member
    Posted 5 years ago #

    Thanks csbartus - that snippet has just saved me a lot of faff.

Topic Closed

This topic has been closed to new replies.

About this Topic