WordPress.org

Support

Support » Themes and Templates » [Resolved] Displaying Only Child Categories of Parent

[Resolved] Displaying Only Child Categories of Parent

  • Hi,

    I’m using WP 2.0.x and I am trying to only display a child category when the user clicks a specific parent category.

    Now the variable which holds the current category is $cat and when I echo it out it works fine. But when I use it in my code it ignores the variable and doesn’t display my child categories at all.

    Works: wp_list_cats(‘sort_column=id&optioncount=0&use_desc_for_title=0&child_of=2’);

    Doesn’t work:
    $cat=2;
    wp_list_cats(‘sort_column=id&optioncount=0&use_desc_for_title=0&child_of=$cat’);

    Can someone shed some light on this? For something that looks so simple this is driving me insane.

    Thanks,

    G.

Viewing 5 replies - 1 through 5 (of 5 total)
  • There’s got to be theme and plugin developer gurus out there who can help me with this simple question? Surely?

    Thanks but no, that doesn’t help me I’m afraid. I’ve already installed that plug-in. It works but only displays child categories beneath parent categories which looks messy on my blog.

    What I am really trying to do is have one list of parent categories in one column and show specific child categories in another column when a user clicks a specific category.

    Has anyone been able to do this?

    A PHP variable will be read as a literal string ($cat instead of 2) when in single quotes, so switch to double-quotes to surround arguments that include a variable:

    wp_list_cats("sort_column=id&optioncount=0&use_desc_for_title=0&child_of=$cat");

    Thank you very much.

    Double quotes, that’s all I was missing. I knew it would be something easy like that.

    I will mark this as resolved and hope it will help others in a similar situation.

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Displaying Only Child Categories of Parent’ is closed to new replies.
Skip to toolbar