exchangeable secondary menu in WordPress

I’ve started to use WP today, and am trying to do some customization to suite my needs.

I’ve chosen one theme with 2 menus top, and let’s call it “mid” menu.

Read More

So Let’s assume that main (top menu) consists of:
(Home, Webs, Apps, Photos, Contacts)

And then, I’d like to have different menus for each selection of first one
for Home – no secondary menu
for Webs – “Mid1” menu that has link to pages (web1, web2, web3, web4…)
for Apps – “Mid2” menu that has link to pages (App1, App2, App3, App4…)
for Photos – “Mid3” menu that has link to pages (Gallery1, Gallery2, Gallery3, Gallery4…)
for Contacts – no secondary menu

Is there maybe such plugin that handle this or should I put some if – then somewhere in the code ?

Tx.

Related posts

Leave a Reply

1 comment

  1. I would use WordPress’s built-in Page heirarchy, then generate the submenus based on that heirarchy.

    So, you’d need to associate each subpage with it’s parent, which you can do on the right sidebar of the WordPress editor, or use a drag and drop plugin like PageMash:

    • Home
      • Webs
        • Web 1
        • Web 2
        • Web 3
        • Web 4
      • Apps
        • App 1
        • App 2
        • App 3
        • App 4
      • Photos
        • Gallery 1
        • Gallery 2
        • Gallery 3
        • Gallery 4
      • Contacts

    Then, add some code to your template (probably page.php) to list children of the current page. You’ll probably have to tweak this to get exactly what you want, this is just to get you started:

    <?php
        /* List the child pages */
            if ($post->post_parent) {
               $ancestors=get_post_ancestors($post->ID);
               $root=count($ancestors)-1;
               $parent = $ancestors[$root];
             } else {
               $parent = $post->ID;
             }
    
              $parent_title = get_the_title($post->post_parent);
              $children = wp_list_pages("title_li=&child_of=". $parent ."&echo=0");
    
              if ($children) { ?>
    
                  <ul>
                     <?php echo $children; ?>
                  </ul>
               <?php }
                    /* If there are no children, do something else, or nothing */
                    else { } ?>