你想做的事是可以做到的。它不太可能真的干净整洁。
您可以通过使用自定义Walker Class
对于wp_nav_menu()
插入时。
class My_Walker_Class extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$output .= sprintf( "\\n<li><a href=\'%s\'%s>%s</a></li>\\n",
$item->url,
( $item->object_id === get_the_ID() ) ? \' class="current"\' : \'\',
$item->title
);
/**
* Here you will need to add a conditional to see if the parent menu item was found
* and if so go into a subroutine that grabs your CPT list. Add it all to $output.
*/
if ( $item->object_id == 111 ) // Match by ID
{
// Call external function that generates CPT list
$output .= my_get_cpt_list();
}
}
}
$args = array(
\'theme_location\' => \'my_theme_location\',
\'menu\' => \'my_menu\',
\'container\' => \'div\',
\'container_class\' => \'\',
\'container_id\' => \'\',
\'menu_class\' => \'menu\',
\'menu_id\' => \'\',
\'echo\' => true,
\'fallback_cb\' => \'wp_page_menu\',
\'before\' => \'\',
\'after\' => \'\',
\'link_before\' => \'\',
\'link_after\' => \'\',
\'items_wrap\' => \'<ul id="%1$s" class="%2$s">%3$s</ul>\',
\'depth\' => 0,
\'walker\' => new My_Walker_Class()
);
wp_nav_menu( $args );
当然,根据需要进行调整,使其实际工作。