Support » Fixing WordPress » styling parent categories while displaying their children

  • Here’s the deal. I’ve got lots of categories, split up by 3 parent categories. I want to display each set of parent categories with its own color scheme on the page, ie if I call an Apple category, which has a parent of Fruit, I want it to show up blue (using css), just as if I called any other category archive with a parent of Fruit. Orange, Banana, Lime– they all show up blue.

    But when I call a category with parent Bread, say Wheat for example, I want to css style it brown. Multi-grain shows up as brown, as does Rye and Pumpernickel.

    The problem is that all I’ve got is the in_category() function, and I don’t really want to have to do an if… else for every single category (would hurt the expandability, if nothing else).

    What I really want is an “in_parent_category($FruitID)” function. I found this (http://wordpress.org/support/topic/37330), but I can’t figure out where to place it in my code, and I figure it needs to be inside the loop anyway, which doesn’t help me with dynamically styling the rest of the page.

    Whew. Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • doh… bump. I need some help on this one.

    this seems like exactly what I want…

    http://wordpress.org/support/topic/35301

    … but it’s not working.

    Ok, got a solution… (searching for the answer is your friend, searching for the answer for three hours is your best friend ever)

    It’s over on the Custom Category Template Page (all the way at the bottom under “Custom Category Template” code) lines 5 & 6. Heck, I’m so happy I’ll reprintthem here.

    <?php $this_category = get_category($cat);?>
    <?php if ($this_category->category_parent == 0) { ?>

    That tests the current category’s parent, which means you can apply any templating based on the category’s parent– ie all “Fruit” parented category pages can be blue, just like I need.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘styling parent categories while displaying their children’ is closed to new replies.