wp_nav_menu sort order?
I’m trying to build a right aligned, wrapping capable wp_nav powered menu.
Is there a way to have it rendered backwards, so that float: right; would work and not mess up the order?
I was hoping for something like this:
<?php wp_nav_menu( array('sort_order' => 'DESC' )); ?>
sort_orderattribute for wp_nav_menu:
I understand that, I was hoping there was another way to do it. Perhaps a filter of some sort?
Not that I know of. Also, it wouldn’t make any sense to have a sort order since the whole point behind wp_nav_menu is that site owners can set up their own custom menu with their preferred order. Are you perhaps looking for a sort order for the default fallback, wp_page_menu? That has a sort_column attribute but not an order one.
It makes complete sense to need to return the values in the reverse of the order the user intended. For instance, I have a main nav where each item floats left, but a footer nav where they float right. The menu appears backwards down in the footer since the first item gets pushed to the far right.
It would be great to be able to reverse the order the elements are spit out.
I have the same issue. I think being able to reverse the order make good sense as well. I’ll post a solution if I find one.
Well this works, but it seems inefficient:
add_filter('wp_nav_menu_objects', create_function('$menu', 'return array_reverse(array_reverse($menu ));'));
I used array_reverse twice to get the order the way I wanted. It works using it only once for the opposite order:
add_filter('wp_nav_menu_objects', create_function('$menu', 'return array_reverse($menu );'));
Put in your theme’s functions.php
Using this function might be a better method, especially for targeting just one menu: http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items
- The topic ‘wp_nav_menu sort order?’ is closed to new replies.