它不应该;\'别那么难。你所要做的就是wp_get_nav_menu_items
滤器
这将向标题等于“”的项目的子菜单添加10篇文章。
function insert_my_posts_to_menu( $items, $menu, $args ) {
$menu_order = count($items);
$child_items = array();
foreach ( $items as &$item ) {
if ( $item->title != \'<SOME MENU ITEM TITLE>\' ) continue;
foreach ( get_posts( array(\'post_type\'=>\'post\', \'numberposts\'=>10 ) as $post ) {
$post->menu_item_parent = $item->ID; // add post to submenu of current item
$post->post_type = \'nav_menu_item\';
$post->object = \'custom\';
$post->type = \'custom\';
$post->menu_order = ++$menu_order;
$post->title = $post->post_title;
$post->url = get_permalink( $post->ID );
$child_items[] = $post;
}
}
return array_merge( $items, $child_items );
}
add_filter( \'wp_get_nav_menu_items\', \'insert_my_posts_to_menu\', 10, 3 );
那你也应该照顾好
current
我想是女同学吧。