Forum

Thread tagged as: Question

Perch Navigation - Show all Sub items

Hi,

how can i show all sub items?

I want to output all the sub items of every parent, but not show the parents

Thanks

Paul Langley

Paul Langley 0 points

  • 3 years ago

Have you tried hiding the parent page in cms backend?

Pages / Page / Settings / Hide from main navigation

Not sure this will work though?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think you probably want the from-path option.

https://docs.grabaperch.com/functions/navigation/perch-pages-navigation/

But from-path would should the sub items for only the specified path?

how do i should all sub items but not any of the parents?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You mean across all paths?

Yeah i want to output every parents sub items, but not output the parents if that makes sense

So output all sub items across the site

Ta

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'll need to filter them out in the template by testing for pageDepth.

Sorry Drew, really struggling with this. I tried below but no luck , any ideas?

<perch:before>
    <ul>
</perch:before>
<perch:pages id="pageDepth">
<perch:if id="pageDepth" value="2">

        <li class="<perch:if exists="current_page">selected</perch:if><perch:if exists="ancestor_page"> ancestor</perch:if> <perch:if exists="subitems"> nav-parent</perch:if>">
            <a href="<perch:pages id="pagePath" />"><perch:if exists="subitems"><span>+</span></perch:if><perch:pages id="pageNavText" /></a>
            <perch:pages id="subitems" encode="false" />
        </li>
</perch:if>
<perch:after>
    </ul>
</perch:after>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What result are you seeing?

Nothing is output at all

i call it like this:

<?php perch_pages_navigation(array( 'levels' => 2, 'template' => 'subitem.html'

)); ?>

Sorry Drew, any ideas or just not possible?

Ta

Hi Paul,

The perch:if statement in your template might need match="eq" for numerical comparisons, i.e.

<perch:if id="pageDepth" value="2" match="eq">
...
</perch:if>
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Paul,

You need to rethink your conditional statement and consider how the subitems are added to the template.

The below means you only output the first sub page. So pages that have a larger page depth won't be included:

<perch:if id="pageDepth" value="2">
</perch:if>

The following includes all sub pages:

<perch:if id="pageDepth" match="gt" value="1">
</perch:if>

What outputs the sub pages is the subitems:

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

You're including the subitems inside the conditional statement so the template never loops through the sub pages.

You probably need something like this instead:

<perch:before>
    <perch:if id="pageDepth" match="neq" value="2">
        <ul>
    </perch:if>
</perch:before>


<perch:if id="pageDepth" match="gt" value="1">
    <li><a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a>   
</perch:if>

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

<perch:if id="pageDepth" match="gt" value="1">
    </li>
</perch:if>


<perch:after>
    <perch:if id="pageDepth" match="neq" value="2">
        </ul>
    </perch:if>
</perch:after>

And control how many levels are output in PHP:

perch_pages_navigation(['levels' => 3]);