2

In my custom wordpress theme I currently have the below loop to the main categories

<?php
$menu = wp_get_nav_menu_object('navigation');
$items = wp_get_nav_menu_items($menu->term_id);
foreach($items as $item)
{
?>
    <li><a href="<?php echo $item->url ?>"><?php echo $item->title ?></a></li>
<?php
}
?> 

So it'll just list out each like so:

  • Cat A
  • Cat B
  • Cat C
  • Cat D

But I have now added some subcategories under Cat B so I would like to have it as so:

  • Cat A
  • Cat B
    • Cat B 1
    • Cat B 2
  • Cat C
  • Cat D

I know what to do regarding the html markup but what php command do I use in the loop to distinguish the subcategories?

2
  • 3
    If this is a nav menu, why not just use wp_nav_menu and let it handle the hierarchical output for you? Jan 10, 2016 at 14:03
  • Correct, sorry new to wordpress, had a custom loop as i thought i could customise it easier (moving existing site into wordpress) but can see you can pass arguments into it which means i can use it
    – odd_duck
    Jan 10, 2016 at 15:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.