是的,这是可能的:
function latest_posts_menu($items, $args) {
//To a Specific Menu
if ($args->theme_location == \'primary\') {
// Parent Menu Item
$items .= \'<li id="menu-item" class="menu-item">
<a href="#">\' . __(\'Latest Posts\', \'textdomain\') . \'</a>
<ul class="sub-menu">\';
// Create Sub Menus
foreach ( get_posts(
array(
\'posts_per_page\'=>10,
\'post_type\' => array(\'post\')
)
) as $post ) {
// Menu Thumbnail. You can change the dimenssion as well as the image class
$thumb = get_the_post_thumbnail( $post->ID, array(24,24), array("class" => "menu-thumb") );
$items .= \'<li class="sub-menu-item">
\'.$thumb.\'
<a href="\'.get_permalink( $post->ID ).\'">\'. $post->post_title .\'</a>
</li>\';
}
// Close The Menu
$items .= \'</ul></li>\';
}
return $items;
}
add_filter( \'wp_nav_menu_items\', \'latest_posts_menu\', 10, 2 );
资料来源:
Display Latest Posts In Menu Item