WordPress.org

Ready to get started?Download WordPress

Forums

Submenu to appear on certain pages (5 posts)

  1. jabbamonkey
    Member
    Posted 2 years ago #

    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 http://www.mydomain.com/sectionnav1/ 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!

  2. esmi
    Forum Moderator
    Posted 2 years ago #

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

  3. jabbamonkey
    Member
    Posted 2 years ago #

    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?

    <?php
      $children = wp_list_pages('include=5,9,23&title_li=&child_of='.$post->ID.'&echo=0');
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>
  4. jabbamonkey
    Member
    Posted 2 years ago #

    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; ?>
      </ul>
    <?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...

  5. jabbamonkey
    Member
    Posted 2 years ago #

    Any help with this?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags