WordPress.org

Ready to get started?Download WordPress

Forums

Need children category names to appear on parent category page (8 posts)

  1. tbaxter
    Member
    Posted 9 years ago #

    This is ridiculous... I've spent hours on what should be a simple task, and looking around the web and at the codex, I'm not the only one.

    Here's the scenario...
    The parent category has an id of 2. When they go to that parent category (let's call it "beer"), I want all the subcategory names to display at the top, with links to those subcategories. In short, I want to provide shortcuts, if people are only interested in "miller" or "molson" and don't want to read all of "beer".

    Now, having the cats display in only one category is as easy as
    'if (cat == "2") {'

    Now, the obvious choice would be list_cats(), but I don't want all cats, only the children of 2. So, lets go with
    'list_cats('child_of=2');'

    Nope.

    How 'bout:
    'list_cats('child_of=2&categories=2');'

    Nope.

    Exclude is no good to me, because there's already a lot of categories and as soon as the client adds a new one (and they will), it will break.

    There is no include, to limit to only one category.

    So does anyone have any ideas? Please?

  2. tbaxter
    Member
    Posted 9 years ago #

    Pretty please?

  3. ColdForged
    Member
    Posted 9 years ago #

    Try wp_list_cats('child_of=2').

  4. tbaxter
    Member
    Posted 9 years ago #

    I shoulda mentioned, I'm on 1.5.

    wp_list_cats returns nothing, no matter how I set it. I think it was deprecated for 1.5.
    list_cats('child_of=2'), like I said above, returns everything, ignoring the child_of argument.

  5. ColdForged
    Member
    Posted 9 years ago #

    list_cats doesn't take an argument list in query string form, it takes explicit arguments. Calling as you are you are setting the optionall parameter to "child_of=2" which makes not one lick of sense.

    wp_list_cats() is not deprecated in 1.5. I'm on 1.5 and 1.5.1-alpha and it works dandy. Calling the function as I did for what I told you works. Are you calling this on categories with emtpy children? If so, call it like this:

    wp_list_cats('child_of=2&hide_empty=0')

  6. tbaxter
    Member
    Posted 9 years ago #

    Weird. I can't get wp_list_cats to return anything, no matter what arguments (or none at all) I give.

  7. garethjmsaunders
    Member
    Posted 9 years ago #

    Does it work outside your if (cat=='2') conditional?

    What I'm trying to ascertain is whether it has something to do with the conditional or the wp_list_cats function.

    Gareth

  8. tbaxter
    Member
    Posted 9 years ago #

    Nope. No matter what I do, I return everything or nothing at all.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.