Forum

Thread tagged as: Question

How to have top nav stay active on detail page

I'm not sure if I can explain this very well so please bear with me.

I have a News and Downloads page (/news-and-downloads/index.php) and within that folder sits the blog (/news-and-downloads/news/) and a list (on the /news-and-downloads/index.php page ) and detail (/news-and-downloads/detail.php) jobs section.

I don't have a drop down and don't want one, what I want is for the 'News and Downloads' tab in the main menu to remain active wherever you are within that folder. How would I do this?

Emily Taylor

Emily Taylor 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The top nav should be an ancestor page - so that will enable you to highlight it.

<perch:if exists="ancestor_page"> class="active"</perch:if>

Hi Drew,

Thanks. I've added that code but it's still not working, must be something silly which I'm missing.

My code is below:

<?php 
    perch_pages_navigation(array(
    'from-path'         => '*',
    'from-level'        => 1,
    'template'          => 'main.html',
    'include-parent'    => true,
    'siblings'          => false,
    'include-hidden'    => false,
    ));
  ?>

Nav template main.html:

<perch:before>
<nav>
<ul class="nav">
</perch:before>
    <li<perch:if exists="current_page"> class="active"</perch:if><perch:if exists="ancestor_page"> class="active"</perch:if>>
        <a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a>
    </li>
<perch:after>
</ul>
</nav>
</perch:after>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does it work if you use the standard perch_pages_navigation() ?