一个菜单的wp_nav_menu_items

时间:2015-09-21 09:40:12

标签: wordpress

我测试了这个教程:http://qnimate.com/creating-a-one-page-wordpress-theme/ 它很棒。 问题是在教程中有一个菜单,而我有2个菜单。 让我知道如何自定义此功能:http://qnimate.com/creating-a-one-page-wordpress-theme/#Linking_Menu_Items_to_Internal_Parts_of_Page 该功能仅适用于主菜单。

代码:

function new_nav_menu_items($items) {
$items = "";
$args = array("post_type" => "page", "order" => "ASC", "orderby" => "menu_order");
$the_query = new WP_Query($args);
if($the_query->have_posts()):
    while($the_query->have_posts()):
        $the_query->the_post();
            $items .= '<li><a href="#post-'. get_the_ID() .'">' . get_the_title() . '</a></li>';           
    endwhile;
else:
    echo "";
endif;
return $items; 
}
add_filter("wp_nav_menu_items", "new_nav_menu_items");

我尝试使用if( $args->theme_location == 'primary' ),但我不知道如何使用它。

谢谢 :)

1 个答案:

答案 0 :(得分:1)

您可以尝试post_type = nav_menu_item。

通过主题&gt;构建菜单菜单。