• Hi all
    First of all, thanks in advance for any help. I’ve searched the forums but haven’t been able to find this specifically.
    I’ve been trying to do something that seems fairly simple yet can’t get it to work:

    I need to display the a list of the child of a category in the sidebar while hiding its parent, and another list of only the parents.

    The main issue is that the each post I have in the blog is inside both the child AND the parent category… Overall I have 10 parent categories, 10 child categories and 10 posts. I’m using the ‘my custom widgets’ to then incorporate them as separate widgets into the sidebar, which is working.

    The reason why I’m doing this is to be able to show the content through 2 different menus (clients and project type) in the sidebar and keep them both highlighted while in the current post.

    I’ve tried using all of these (separately)
    OPTION 1)
    wp_list_categories(‘orderby=ID&title_li=&depth=1’); –to show parents
    wp_list_categories(‘orderby=ID&title_li=&depth=2’); –to show children only, BUT it shows parents as well.

    OPTION 2)
    wp_list_categories(‘orderby=ID&title_li=&depth=1’); –to show parents
    wp_list_categories(‘orderby=ID&title_li=&child_of=3,4,5,6,ETC’); — to show children, BUT displays “no categories”

    OPTION 3)
    wp_list_categories(‘orderby=ID&title_li=&depth=1’); –to show parents
    if (in_category(‘3,4,5,6’)) { wp_list_categories(‘orderby=id&title_li=&child_of=3,4,5,6’); } –to show childrent, But displays “no categories”

    Excuse me if this sounds overly confusing… I can clarify further if needed.

    Thanks

    C

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could use include and exclude. If you have a small ammount of categories I don’t see why not.

    <?php
    wp_list_categories(‘orderby=name&include=3,5,9,16’); ?>

    <?php
    wp_list_categories(‘orderby=name&show_count=1&exclude=10’); ?>

    Thread Starter coche09

    (@coche09)

    Hey recogn1ze, thanks a bunch for the response.

    I just tested what you mentioned and one of the issues I found with that method is that it doesn’t keep the categories highlighted: when you exclude the parent of one of the child categories, the child category looses the styling, I imagine it’s because it doesn’t ‘know’ it has a parent? This highlighting is actually THE reason why I’m trying to do this through categories so I’d like to have that working.

    This ‘partially’ works:
    wp_list_categories(‘orderby=ID&title_li=&depth=1’); –show parents highlighted in css through current-cat.
    wp_list_categories(‘orderby=ID&title_li=’);– shows both parent and child highlighted in css through current-cat, but need to display only the child.

    It makes me wonder if there is a way to target the styling then to only the child while checking if it has a parent while having the parent excluded…

    Any ideas if/how this could work?

    Cheers

    C

    Thread Starter coche09

    (@coche09)

    I should add, the other way I tried getting this to work was to do it by showing categories and recent posts in the sidebar. However, I couldn’t get the post title to highlight when the category to which the post belongs is selected or viceversa: highlight the category while the post is selected.

    I can highlight the current category though through the css.

    I haven’t been able to find much about highlighting the post title in the sidebar.

    Thanks

    C

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display child but hide parent in sidebar?’ is closed to new replies.