I would like to add level classes to each li when echoing the results of wp_list_pages. Currently, I’m using:
<?php
wp_nav_menu(array('theme_location' => 'main_menu', 'container' => '', 'menu_class' => 'fR clearfix', 'menu_id' => 'nav'));
<?php } ?>
The desired output would be:
<ul class="menu">
<li class="page_item page-item-9 level-0 current_page_item"><a href="" title=""></a>
<ul class="children expanded" style="display: block; ">
<li class="page_item page-item-40 level-1"><a href="" title=""></a></li>
<li class="page_item page-item-43 level-1"><a href="" title=""></a></li>
<li class="page_item page-item-45 level-1"><a href="" title=""></a></li>
<li class="page_item page-item-47 level-1"><a href="" title=""></a></li>
</ul>
</li>
<!-- So on -->
</ul>
Is this possible to have the desired output? please help!
There isn’t a direct way to do this.
You can use the wp_nav_menu_objects filter and manipulate the menu item’s classes.
Here is the code for you:
It’s best to use a custom walker to add that class. See
Cleaner output for wp_nav_menu() and Improve your WordPress Navigation Menu Output and T5_Nav_Menu_Walker_Simple â Gist
it will help you…
http://codex.wordpress.org/Function_Reference/wp_list_pages