Support » Fixing WordPress » Submenu to appear on certain pages

  • My wordpress site has a top menu, with sub items dropping down (so, if you mouseover a parent nav item, it’s children drop down).

    I’m looking to add an additional side nav menu for these section pages (so, if it is the ABOUT section, the side nav will list only the children of that section (such as HISTORY, WHO WE ARE, MISSION). I want this menu to appear only on pages within that nav item (so, only on the ABOUT page, and the children of that page). Is there an easy way to do this?

    I’m not great with PHP… but I figure I could add IF-THEN statements to my templates and say…
    IF the URL contains THEN show menu for Section1.
    Or, if that’s not possible, is there a way to say…
    IF the page is a child of “sectionnav1” THEN show menu for Section1.

    How would I do this using PHP?

    Additionally, is there a way to automatically print out the menu. So, if the THEN statement run, it will automatically list out the children of the page? Or do I need to hard code the menu’s into my templates ?

    Please let me know. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi


    Forum Moderator

    Try using the is_page conditional. And this Codex section shows some sub-page coding examples.

    That looks helpful. I’ll check it out for the sidenav.

    At the moment, my topnav is currently hard coded into the template. Using the example that page that you sent, if I wanted to make the main nav driven by the CMS … how do I do the following….

    I want to choose which pages are listed in the main nav (because I dont want an admin user to add a random page to the site, and have it automatically appear in the top nav), and for THOSE main nav items, have them print out their children subnav items.

    So, to include pages I want in the main list, I would use the ‘include=5,9,23’ … and then to print the children I use the ‘title_li=&child_of=’. Correct?

      $children = wp_list_pages('include=5,9,23&title_li=&child_of='.$post->ID.'&echo=0');
      if ($children) { ?>
      <?php echo $children; ?>
      <?php } ?>

    I’ve tried this… but it didn’t work:

    <?php $children = wp_list_pages('include=2,52,11,41,50,54&sort_column=menu_order&title_li='.$post->ID.'&echo=0' );
      if ($children) { ?>
      <ul id="navlist">
      <?php echo $children; ?>
    <?php } ?>

    It prints out “2” … and then the main nav are the subnav items (when I mouseover the 2, the main menu drops down). The main menu needs to print at the top level, and the subnav needs to drop down…

    Any help with this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Submenu to appear on certain pages’ is closed to new replies.