list current cat's child cats' posts with nesting (3 posts)

  1. lorensson
    Posted 4 years ago #

    Hi there guys – I'm using some code I found which list the current category's child categories and their posts within each category. I'm pulling in custom fields from each post. What I want to do is update this code to allow me to style my category titles to differentiate between child categories and child-child categories. So for example, if my categories are like this structure:

    • Food
      • Fruit
        1. Apples
        2. Bananas
        3. Peaches
    • Toys
      • Cars
        1. Ferraris
        2. Porsches

    I want to 'print' a different li class for my 3rd level categories, like 'Apples'. My code currently treats all category titles the same, but I want to be able to print something different if it's a child-child category – like 'Apples' – so I can style the title differently. How can I tell in the code if it's a child-child category? I hope that makes sense, it's all a bit confusing.

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. mikedev
    Posted 4 years ago #

    If you are unable to add the class the way you want, you can probably style the different levels with advanced CSS without adding the class. Here are some resources:

  3. lorensson
    Posted 4 years ago #

    Hi Mike, thanks for the reply. That's a good idea but unfortunately the code I'm using (above) isn't 'printing' nested lists – it's putting all categories regardless of hierarchy at the same top level ul — so I guess two things would work for me:

    1. get the code to print nested lists according to WP category hierarchy instead of all at same level, or
    2. leave the code printing them at the same level but giving the 3rd level category titles a new class

    Sorry about the code. Have used Pastebin – hope this is the right way to do it.

    Pastebin: http://pastebin.com/s7Mp8PrW

Topic Closed

This topic has been closed to new replies.

About this Topic