我不能百分之百确定我是否正确,但这可能会解决你的问题:
add_filter( \'wp_nav_menu_items\', \'fx_user_menu\', 10, 2 );
function fx_user_menu( $items, $args ) {
if ($args->theme_location == \'primary\') {
$myposts = get_posts( array(
\'category\' => <YOUR CATEGORY ID GOES HERE>,
\'posts_per_page\' => 5
) );
foreach ( $myposts as $post ) {
// you should not use the_title and the_permalink outside of The Loop - they won\'t work correctly
$items .= \'<li><a href="\' . get_permalink($post->ID) . \'">\' . apply_filters(\'the_title\', $post->post_title) . \'</a></li>\';
}
}
return $items;
}