WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] List parent category with child categories? (7 posts)

  1. gashface
    Member
    Posted 2 years ago #

    Is there a way to list the parent category with the child categories? I am currently trying to create a sidebar that looks something like this:

    Parent Category
    Child Cat 1
    Child Cat 2
    Child Cat 3

    However I can only find listing codes that either list the parent category or the children.

    <?php wp_list_categories('use_desc_for_title=0&child_of=24'); ?>

    The code above I'm using I tried adding include=24& but that did nothing, also how do I get rid of the title 'categories' I tried the usual title=li but that didn't work either.
    Any help appreciated, thankyou!

  2. Joseph
    Member
    Posted 2 years ago #

    Use this:

    <?php wp_list_categories('include=24,'.implode(',',get_term_children(24, 'category')).'&title_li='); ?>
  3. gashface
    Member
    Posted 2 years ago #

    thankyou that worked perfectly!

  4. gashface
    Member
    Posted 2 years ago #

    One more question, as a bonus. I'm using current-cat to highlight the current category as a different colour.

    On the parent it highlights all of the children as well, is there a way that on the parent category page it will only highligh the parent in the list or not?

  5. Joseph
    Member
    Posted 2 years ago #

    Two easier methods I can think of:

    1. Depending on how it's highlighted, you can write the CSS so that it "un-highlight" the children because the children categories are a list within a list.

    2. If the parent category is created before the children (lower integer ID), you can make it so that the children are not a list within the parent by setting

    hierarchical=0
    orderby=ID

    Note that the children categories will no longer be listed alphabetically after the parent unless they were created in an alphabetical order.

  6. Winstyle
    Member
    Posted 2 years ago #

    Fank you and me helped

  7. gashface
    Member
    Posted 2 years ago #

    This works in CSS:

    #sidebar li.current_page_item a{color: #00ADEE;}
    #sidebar ul.children a{margin: 0px 0px 0 20px; #808184;}

    (:

    thanks

Topic Closed

This topic has been closed to new replies.

About this Topic