I'm working on a custom menu that is particularly complex and I like to know which is the right way to build it.

This is the structure of my menu:

- Home (is a PAGE)

- Information (Is a PAGE with a second level menu)
        |_________Items are the post for the category "information"

- Data (It hasn't a PAGE, only a second level menu)
        |_________Items are the posts for the category "data"

In your opinion which is the best way to build a menu like this? is it possible to build it from the WP backend or is better to create it just from code in the template?


It is possible to do this using the backend nav menu support, using classes as markers that are then picked via the walker_nav_menu_start_el filter ( which then do queries to grab posts and insert their markup )


add_filter( 'walker_nav_menu_start_el', 'menu_show_media_post', 10, 4 );

function menu_show_media_post( $item_output = '', $item = '', $depth = '', $args = '' ) {
    global $post;

    $query = false;

    if ( is_array( $item->classes ) ) {

        foreach( $item->classes as $class ) {
            if ( $class == 'some_marker_class_to_watch_for_goes_here') {
                $query = true;

    if ( $query ) {
        $args = array(
        $q = new WP_Query($args);
                // do stuff and append output to $item_output, dont echo it out
    return $item_output;

All in all this is a fairly advanced level thing to do.

If you want to go a step further you can add UI controls to the menu pull outs themselves, and store the data as post meta for each menu nav item. This would be a better way of doing it, but it's not for the faint of heart as it requires JS code in the admin backend, and a custom walker to render out the initial html for the nav admin interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.