WordPress.org

Ready to get started?Download WordPress

Forums

Showing only the children of categories (2 posts)

  1. dcomfort
    Member
    Posted 9 years ago #

    I am several different categories, with sub-categories under each of those categories. I would like to show only those categories which are children of that category when I am "drilling" down into a category. I cannot find any way to configure wp_list_cats to do that and there doesn't seem to be any hack or plugin to accomplish this task. Essentially I wanted a nested directory structure with lower levels hidden until I drill down into those categories

  2. cacophoney
    Member
    Posted 9 years ago #

    Hope I do understand your message correctly.. I want to do more or less the same thing, too.

    First I make another template for category page using the mod_rewrite thingie (by modifying the .htaccess file -- there's a tutorial on that but i dont have my bookmarks so i cant give you the link, sorry).

    Then in my category.php page, I write this:
    <?php wp_list_cats('child_of=$cat'); ?>
    where I want my subcategory links to display.
    To show only subcategories one level down (ie hiding subcategories of a subcategory, if any), I only use CSS (display: none).

    The only problem is, I need to put a text ("subcategories:") before the subcategories link, so my code goes like:
    <ul id="subcat">
    <li>subcategories: </li>
    <?php wp_list_cats('child_of=$cat'); ?>
    </ul>

    When a category has no further subcategories under it, it would still display the text "subcategories:".
    What I need is the code to hide that
    <li>subcategories: </li>
    part IF there's no subcategories under a category. I know I probably should use some "if-then" thingie using PHP but I know positively nothing about php so I'd be glad if anyone can help.

    Loads of thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.