I need to get the nr. of items in the primary navigation menu. I need this to determine the width in percentage of each list item. So I also need to change/add to the css width attribute of the list items somehow, which I haven't figured out how to do yet either... As a first attempt I've tried the function wp_get_nav_menu_object. I am developing a child theme off of the twentyfifteen template. I have made a custom home page where I load the primary navigation (copied straight from the sidebar.php file in the original theme folder) and call wp_get_nav_menu_object straight after that using the code snippet
<?php if (has_nav_menu('primary')) : ?>
<nav id="site-navigation" class="main-navigation" role="navigation">
<?php
// Primary navigation Menu
wp_nav_menu(array(
'menu_class' => 'nav-menu',
'theme_location' => 'primary',
));
// none of these seem to work...
//$menu = wp_get_nav_menu_object('menu-primary-menu');
$menu = wp_get_nav_menu_object('primary');
echo $menu->count;
?>
</nav> <!-- /.main-navigation -->
<?php endif; ?>
I know I could go with a jQuery/JavaScript solution (which is what I'm doing at the moment in fact), but that's not ideal. I'm beginning to suspect that for what I want to do I need to create my own custom primary navigation menu with the help of the Walker class. Could anybody advise me on what the best approach would be?
nr.
? sorry for asking. I am not good with abbreviation..