Forum

Thread tagged as: Question, Problem, Blog

Blog section menu within main site navigation

I've created a conditional menu that displays a dropdown menu if a page has subpages. My client wants mutiple sections within their blog, so I want to create a dropdown from the Blog link in the sites main menu.

I'm not sure how to do this though! This is the code for my current navigation template –

<perch:before>
    <perch:if id="pageDepth" value="1" match="eq">
        <ul class="main clearfix">
    <perch:else />
        <ul class="dropdown-menu">
    </perch:if>
</perch:before>
    <li<perch:if exists="current_page"> class="active"</perch:if>>
    <perch:if exists="subitems">
        <li class="dropdown">
            <a data-toggle="dropdown" class="dropdown-toggle" href="#"><perch:pages id="pageNavText" /> <b class="caret"></b></a>
            <perch:pages id="subitems" encode="false" />
        </li>
    <perch:else />
        <a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a> 
    </perch:if> 
    </li>
<perch:after>
    </ul>
</perch:after>

Hoping somebody can help. Thank you!

David Maxwell-Wood

David Maxwell-Wood 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What would the drop down have? Section titles?

Yup, that's correct – section titles linked to the individual blog sections.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use perch_blog_sections() to get the list of sections and pass it into the template:

PerchSystem::set_var('blog_sections', perch_blog_sections(array(), true));

and then output it in the template:

<perch:if id="pagePath" match="eq" value="/blog/index.php">
    <perch:pages id="blog_sections" encode="false" />
</perch:if>

Thanks Drew. It's so nearly there, but I need to wrap the blog sections with <ul class="dropdown-menu">.

I've tried a number of things but it's only outputting <ul>. Is there a template file I can set for this dropdown?


<perch:before> <perch:if id="pageDepth" value="1" match="eq"> <ul class="main clearfix"> <perch:else /> <ul class="dropdown-menu"> </perch:if> <perch:if id="pagePath" match="eq" value="/news/"> <ul class="dropdown-menu"> </perch:if> </perch:before> <li<perch:if exists="current_page"> class="active"</perch:if>> <perch:if exists="subitems"> <li class="dropdown"> <a data-toggle="dropdown" class="dropdown-toggle" href="#"><perch:pages id="pageNavText" /> <b class="caret"></b></a> <perch:pages id="subitems" encode="false" /> </li> <perch:else /> <perch:if id="pagePath" match="eq" value="/news/"> <li class="dropdown"> <a data-toggle="dropdown" class="dropdown-toggle" href="#"><perch:pages id="pageNavText" /> <b class="caret"></b></a> <perch:pages id="blog_sections" encode="false" /> </li> <perch:else /> <a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a> </perch:if> </perch:if> </li> <perch:after> </ul> </perch:after>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What template is your perch_blog_sections() call using?

Drew, thanks for pointing this out.

I created a link only template and set the template in the perch_blog_sections() array within runtime.php – now the menu is giving me the desired effect.