We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question

Is it possible to limit the number of navigation items output?

I'd like to limit the number of top level navigation items.

I'd also like to only limit them by template e.g. I want to limit the amount of header items in the header, but the footer navigation items should not have this restriction.

Is this possible?

Jay George

Jay George 2 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd create a navigation group and hand-select the items you want to be included in that group.

OK, I understand that, but this is more to prevent the user getting trigger happy.

From your answer, I'm presuming this is not possible? I'll find a way around if not, but wanted to check I wasn't missing something.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's always possible. You can test for the current perch_item_index in the template and only output the link if it's below your chosen threshold.

For anyone looking for the solution, it would be something like this:

<perch:before>
    <ul class="nav-menu">
</perch:before>
        <!--* Output a maximum of 5 items -->
        <perch:if id="perch_item_index" match="lt" value="6">
        <li<perch:if exists="current_page"> class="current-menu-item"</perch:if><perch:if exists="ancestor_page"> class="current-menu-ancestor"</perch:if>>
            <a href="<perch:pages id="pagePath" />"><span itemprop="name"><perch:pages id="pageNavText" /></span></a>
            <perch:pages id="subitems" encode="false" />
        </li>
        </perch:if>
<perch:after>
    </ul>
</perch:after>