2016-09-30 31 views
0

我試圖在左側邊欄上顯示當前頁面的子菜單的鏈接。但訂單不適用於菜單!有什麼問題?wp_list_pages通過頂級導航菜單順序排序和wordpress上的孩子

<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/

側邊欄鏈接順序必須是相同頂部菜單順序

+0

如何頂欄菜單中創建? –

+0

@ this.lau_ \t

Amino

回答

0

我發現這個http://wpsmith.net/2011/how-to-get-all-the-children-of-a-specific-nav-menu-item/

,並寫了這個代碼,因此它固定!

功能get_nav_menu_item_children($菜單,$深度=真){

$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; 

}

使用

$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;