WordPress.org

Ready to get started?Download WordPress

Forums

wp_nav_menu sort order? (11 posts)

  1. Drew Baker
    Member
    Posted 3 years ago #

    Hey Guys,
    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' )); ?>

    Thanks!

  2. Drew Baker
    Member
    Posted 3 years ago #

    Bump?

  3. esmi
    Forum Moderator
    Posted 3 years ago #

    There's no sort_order attribute for wp_nav_menu:
    http://codex.wordpress.org/Function_Reference/wp_nav_menu

  4. Drew Baker
    Member
    Posted 3 years ago #

    I understand that, I was hoping there was another way to do it. Perhaps a filter of some sort?

  5. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  6. jcross
    Member
    Posted 2 years ago #

    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.

  7. Mindshare Studios, Inc.
    Member
    Posted 2 years ago #

    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.

  8. Mindshare Studios, Inc.
    Member
    Posted 2 years ago #

    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

  9. Steven Jones
    Member
    Posted 2 years ago #

    Is there any way to filter it for just one menu?

  10. Mindshare Studios, Inc.
    Member
    Posted 2 years ago #

    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

  11. jevets
    Member
    Posted 2 years ago #

    Best bet is to rework the HTML and CSS so that you can avoid floating the menu items right. Maybe you could float the menu's container right, then float the list items left within that container.

Topic Closed

This topic has been closed to new replies.

About this Topic