Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress plugin for automatic category menus Reply To: WordPress plugin for automatic category menus

#210081
khommon
Participant

I was wondering the same thing and found these two plugins:

http://jamescollings.co.uk/wordpress-plugins/jc-submenu/

Allowing you to automatically populate wordpress menu items with post types, taxonomies, and pages.

&

https://github.com/wp-plugins/category-posts-in-custom-menu

This plugin automatically replaces selected Category / Post Tag / Custom Taxonomy links in a Custom Menu by a list of their posts/pages

At the same time I’m evaluating pro/cons of building a custom one using the following core functions:

register_nav_menu()
unregister_nav_menu()
wp_get_nav_menu_items()
wp_nav_menu_update_menu_items()

A basic snippet to build a menu from a query resut looks something like:

$menu_name = 'My Dynamic Menu';
$menu_exists = wp_get_nav_menu_object( $menu_name );

if( !$menu_exists){
    $menu_id = wp_create_nav_menu($menu_name);
    foreach($myQueryResult->posts as $post) {
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' =>  $post->post_name,
            'menu-item-classes' => 'optionalClassName',
            'menu-item-url' => get_permalink($post->ID),
            'menu-item-status' => 'publish'
        ));
    }
}