0

Im trying to show a box on left sidebar with links of current page's sub menus. but order is not applying same as menu! whats the problem?

<div class="sidebar-box">
                <div class="sidebar-box-title">
                    <h4><?php echo get_the_title($post->post_parent); ?></h4>
                </div>
                <ul class="links">
                    <?php wp_list_pages('sort_order=asc&title_li=&sort_column=menu_order&depth=1&child_of='.$post->post_parent); ?>
                </ul>
            </div> 

DEMO: http://www.testhosting.co.uk/speedshealthcare/healthcare-supplies/care-home-pharmacy/

3 Answers 3

1

Because you are ordering only by menu_order, rather than menu_order post_title. In fact, you can just get rid of your sort_* arguments as wp_list_pages will output the correct natural order by default.

2
  • Not working! added this code ` $args = array( 'title_li' => "", 'sort_column' => 'menu_order post_title', 'depth' => 1, 'child_of' => $post->post_parent ); wp_list_pages($args);` you can see order is wrong still
    – Amino
    Commented Sep 30, 2016 at 11:17
  • You need a comma, but like I say, you should just get rid of the argument Commented Sep 30, 2016 at 11:19
0

I found this http://wpsmith.net/2011/how-to-get-all-the-children-of-a-specific-nav-menu-item/

and wrote this code, so it fixed!

function get_nav_menu_item_children( $menu, $depth = true) {

 $post_id = $post_id ? : get_the_ID();
$menu_items = wp_get_nav_menu_items($menu);

$parent_item_id = wp_filter_object_list($menu_items, array('object_id' => $post_id), 'and', 'menu_item_parent');

if (!empty($parent_item_id)) {
    $parent_item_id = array_shift($parent_item_id);
    $parent_post_id = wp_filter_object_list($menu_items, array('ID' => $parent_item_id), 'and', 'object_id');

    if (!empty($parent_post_id)) {
        $parent_post_id = array_shift($parent_post_id);

       $parent_id=  get_post($parent_post_id)->ID;
    }
}




$nav_menu_item_list = array();

foreach ((array) $menu_items as $nav_menu_item) {

    if ($nav_menu_item->post_parent == $parent_id) {

        $nav_menu_item_list[] = $nav_menu_item;

    }
}
return $nav_menu_item_list;

}

Usage

 $menuSide=get_nav_menu_item_children('Main menu');

                      foreach ($menuSide as $link):
                        $active='';
                          if(intval($post->ID)===intval($link->object_id)){
                              $active=' current_page_item ';

                          }
                        echo ' <li class="'.$active.'"><a  href="'.$link->url.'">' . $link->title . '</a></li>';
                    endforeach;
0

You should use the page editor and set the 'order'. Setting the page order is what the problem here is. Once you set the order (lowest to highest) it will display in wp_list_pages in that order and not the default order which is page_title as @TheDeadMedic has stated. By default wp_list_pages lists pages alphabetically by their post_title. So if you want anything different from that, you are going to have to go to your pages in the dashboard one-by-one, and set those orders. After that, you will be all set.

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.