samedi 3 janvier 2015

Counting the menu children items of a parent


Is there an easy way to count the menu items of a parent item? I can do it fine by page_id but I ran into a problem when I use a custom menu item, such as 'Pages' which is effectively just a dead link so that anyone can hover over and the child elements for my dropdown menu.


I'm currently working with the following:



$menu_name = 'primary';
$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object($locations[ $menu_name ]);
$menu_items = wp_get_nav_menu_items($menu->term_id, array('order' => 'DESC'));


Is there anyway to do it without having to go through a loop? Is there no WordPress function for such an issue?


It's been a late night so maybe I've made a really easy problem hard.





Aucun commentaire:

Enregistrer un commentaire