WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Displaying Only Child Categories of Parent (6 posts)

  1. lowestformofwit
    Member
    Posted 6 years ago #

    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.

  2. lowestformofwit
    Member
    Posted 6 years ago #

    There's got to be theme and plugin developer gurus out there who can help me with this simple question? Surely?

  3. moshu
    Member
    Posted 6 years ago #

  4. lowestformofwit
    Member
    Posted 6 years ago #

    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?

  5. Kafkaesqui

    Posted 6 years ago #

    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");

  6. lowestformofwit
    Member
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic