Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Check if no child category exists
Hi,
I am generating a nested expand/collapse menu of parent and child categories. With my current setup, only the child categories have permlinks, and the parent category’s title simply shows/hides the children on click.
I now have a need to check if a parent category has any children or not. If no children exist, then apply a permlink to that parent category.
Here’s my code:
<ul id="menu">
<txp:category_list children="0" wraptag="" break="li">
<h6 <txp:if_category name='<txp:category />'>class="expanded"<txp:else />class="collapsed"</txp:if_category>><txp:category title="1" /></h6>
<txp:category_list parent='<txp:category />' exclude='<txp:category />' wraptag="ul" break="" class="">
<li><txp:category title="1" link="1" section="product-catalogue" /></li>
</txp:category_list>
</txp:category_list>
</ul>
Please help :)
Offline
#2 2011-06-21 18:03:21
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Check if no child category exists
<ul id="menu">
<txp:category_list children="0" wraptag="" break="li">
<txp:variable name="has-children" value='<txp:category_list parent=''<txp:category />'' exclude=''<txp:category />''>yes</txp:category_list>' />
<h6<txp:if_category name='<txp:category />'> class="expanded"<txp:else /> class="collapsed"</txp:if_category>>
<txp:if_variable name="has-children" value=""><txp:category title="1" link="1" /><txp:else /><txp:category title="1" /></txp:if_variable>
</h6>
<txp:category_list parent='<txp:category />' exclude='<txp:category />' wraptag="ul" break="" class="">
<li><txp:category title="1" link="1" section="product-catalogue" /></li>
</txp:category_list>
</txp:category_list>
</ul>
Offline
Re: Check if no child category exists
Thanks a ton!
Tagmaster Els, to the rescue again :)
Offline
#4 2015-07-10 13:02:42
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: Check if no child category exists
For you speed freaks out there, here an improved version of the code. Reason:
etc wrote #293007:
yields an extra (and unnecessary) db query per category.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Pages: 1