我是在自己寻找答案时偶然发现你的问题的。下面是我如何让代码为我工作的:
function new_nav_menu_items( $items, $args ) {
if ( $args->menu == \'primary\' ) {
$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" );