2016-04-24 7 views

答えて

0

ADD_FILTER( 'wp_get_nav_menu_items'、 'display_lasts_ten_posts_for_categories_menu_item'、10,3)。 header.phpの wp_nav_menuで

function display_lasts_ten_posts_for_categories_menu_item($items, $menu, $args) { 

$menu_order = count($items); 
$child_items = array(); 

foreach ($items as $item) { 
if ('category' != $item->object || ('category' == $item->object && get_category_children($item->object_id))) 
continue; 
$category_ten_last_posts = array(
'numberposts' => 3, 
'cat' => $item->object_id, 
'orderby' => 'date', 
'order' => 'DESC' 
); 

foreach (get_posts($category_ten_last_posts) as $post) { 
$post->menu_item_parent = $item->ID; 
$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); 
} 

(配列( 'theme_location' => 'プライマリ'、 'menu_class' => 'display_lasts_ten_posts_for_categories_menu_item'));

関連する問題