Confused on Navigation and showing just subitems of one section

  • I'm working on a site that is bigger than most sites I've worked on and I'm having troubles understanding how to properly implement subitems in navigation to only show the ones that apply.


    For Example Navigation when on a main About Page (HOME>>About>>Child Pages):


    Full Left Navigation on the About Page:

    • Fast Facts
    • Welcome Letter
    • Board of Trustees
      • Meeting Notes
      • Finance Info
      • Resolutions
    • Organization Charts
      • Org Section 1
      • Org Section 2
      • Org Section 3
    • Calendar

    So I have no problem displaying all the links in the left nav. However, what I'm trying to do is when I'm on the Board of Trustees page/sub pages I would want it to look like this (note: without the sub pages of Organization Charts showing and when on the Org Charts to not have the Board sub pages showing):


    • Fast Facts
    • Welcome Letter
    • Board of Trustees
      • Meeting Notes
      • Finance Info
      • Resolutions
    • Organization Charts
    • Calendar

    Is this possible without having to create a custom template for each section? It seems there would be a way, I'm just confused on how to implement it. I looked at this page: https://docs.grabaperch.com/templates/navigation/ and can see how to see if subitems exist, but can't find an example of how you would implement it with the following:


    Template:

    <?php perch_pages_navigation(array(

    'from-path'=>'/about-us/',

    'template' => array('left_nav.html'),

    'levels'=>2

    )); ?>


    left_nav:

    <perch:before>

    <ul id="left-nav">

    </perch:before>

    <li<perch:if exists="current_page"> class="selected"</perch:if><perch:if exists="ancestor_page"> class="ancestor"</perch:if>>

    <a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a>

    <perch:pages id="subitems" encode="false" />

    </li>

    <perch:after>

    </ul>

    </perch:after>


    Thanks in advance for help.

  • Matt A

    Approved the thread.
  • If I am reading your question correctly, what you want to happen is the default settings.


    You shouldn't need to do anything custom for it behave as you want, if using:


    And you click into Board of Trustees, Meeting Notes, Finance Info, Resolutions the HTML markup generated for each page will be:

    • Fast Facts
    • Welcome Letter
    • Board of Trustees
      • Meeting Notes
      • Finance Info
      • Resolutions
    • Organization Charts
    • Calendar
  • Ah, sorry, completely blanked this looking at my own code, what you need to add is 'only-expand-selected' => true


    PHP
    1. <?php
    2. perch_pages_navigation([
    3. 'levels' => 2,
    4. 'only-expand-selected' => true,
    5. ]);
    6. ?>

    You are awesome! This has been driving me crazy. I knew there had to be a way without customizing every navigation. Thanks again for your help!