Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I have a number of top-level categories including "News" and "Sport". They each have multiple levels of child categories as shown below.

  • News

    • Australia
      • NSW
        • Sydney
  • Sports

  • Cycling

    • Road Cycling
    • BMX
  • Triathlon

In my loop I want to display a single category - what ever is the deepest child category of "Sport".

I have found some code on StackOverflow that does returns the deepest child categoryreturns the deepest child category, but not from a specific category. It returns the the deepest child category from all top-level categories. So if a post is in two categories (Sydney and Triathlon) the code shows Sydney as the deepest child category. I somehow need to specify that which top-level category I want the deepest child to come from. In this case that would be "Sport" and the deepest child cat would therefore be "Triathlon".

I have a number of top-level categories including "News" and "Sport". They each have multiple levels of child categories as shown below.

  • News

    • Australia
      • NSW
        • Sydney
  • Sports

  • Cycling

    • Road Cycling
    • BMX
  • Triathlon

In my loop I want to display a single category - what ever is the deepest child category of "Sport".

I have found some code on StackOverflow that does returns the deepest child category, but not from a specific category. It returns the the deepest child category from all top-level categories. So if a post is in two categories (Sydney and Triathlon) the code shows Sydney as the deepest child category. I somehow need to specify that which top-level category I want the deepest child to come from. In this case that would be "Sport" and the deepest child cat would therefore be "Triathlon".

I have a number of top-level categories including "News" and "Sport". They each have multiple levels of child categories as shown below.

  • News

    • Australia
      • NSW
        • Sydney
  • Sports

  • Cycling

    • Road Cycling
    • BMX
  • Triathlon

In my loop I want to display a single category - what ever is the deepest child category of "Sport".

I have found some code on StackOverflow that does returns the deepest child category, but not from a specific category. It returns the the deepest child category from all top-level categories. So if a post is in two categories (Sydney and Triathlon) the code shows Sydney as the deepest child category. I somehow need to specify that which top-level category I want the deepest child to come from. In this case that would be "Sport" and the deepest child cat would therefore be "Triathlon".

Source Link

Display the deepest child category from Category X (in loop)

I have a number of top-level categories including "News" and "Sport". They each have multiple levels of child categories as shown below.

  • News

    • Australia
      • NSW
        • Sydney
  • Sports

  • Cycling

    • Road Cycling
    • BMX
  • Triathlon

In my loop I want to display a single category - what ever is the deepest child category of "Sport".

I have found some code on StackOverflow that does returns the deepest child category, but not from a specific category. It returns the the deepest child category from all top-level categories. So if a post is in two categories (Sydney and Triathlon) the code shows Sydney as the deepest child category. I somehow need to specify that which top-level category I want the deepest child to come from. In this case that would be "Sport" and the deepest child cat would therefore be "Triathlon".