First, have a custom post type. Now you will see custom post subcategory as sub menu. For example: I have created a custom post type the name of “news”. It has some posts under “news”. You write this code in function.php.
[source]
<?php
add_filter(‘wp_nav_menu_items’, ‘add_cn_news’, 10, 2);
function add_cn_news($items, $args) {
$pattern = ‘News</a></li>’;
$temp_items = ”;
if ( have_posts() ) :
$temp_items .= ‘News</a><ul>’;
query_posts( ‘post_type=news&posts_per_page=-1’ );
while ( have_posts() ) : the_post();
$temp_items .= ‘<li><a href="’ . get_permalink( ) . ‘">’ . get_the_title() . ‘</a></li>’;
endwhile;
$temp_items .= ‘</ul></li>’;
$replacement = $temp_items;
$temp_menu = str_replace($pattern, $replacement, $items);
else :
$temp_items = ”;
endif;
return $temp_menu;
}
?>
[/source]
Finally, you will see sub menu under News page.
