Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-10-08 09:46:53

txpdevcoder
Member
Registered: 2012-06-07
Posts: 58

Custom Category List

I have a problem with a category list, i’m hoping someone knows the answer.

I have a category list that dynamically builds up a list of team members and the articles set to those categories. This code works fine but what i need to do is exclude categories that do not have any articles assigned to them. How do I modify the below so that it checks if a category has content or not? Im sure i can use a variable or something somehow but i’ve been going round in circles.

Any help would be appreciated. Thanks!

<txp:category_list section="meet-the-team" parent="meet-the-team" exclude="meet-the-team,directors" break="">
<h2 class="accordion-header"><txp:category title="1" /></h2>
<div class="accordion-content"> 
<ul class="teampeoplelist">
<txp:article_custom section="meet-the-team" category='<txp:category />' wraptag=""  break="">
<li><txp:article_image />
<h1><txp:title /></h1>
<txp:body />
</li>
</txp:article_custom>
</ul>
</div>
</txp:category_list>

Last edited by txpdevcoder (2013-10-08 09:49:07)

Offline

#2 2013-10-08 09:55:55

etc
Developer
Registered: 2010-11-11
Posts: 5,393
Website GitHub

Re: Custom Category List

Like this (mind the linebreaks)?

<txp:category_list section="meet-the-team" parent="meet-the-team" exclude="meet-the-team,directors" break="">
<txp:variable name="catlist"><txp:article_custom section="meet-the-team" category='<txp:category />' wraptag="ul" break="li" class="teampeoplelist">
<txp:article_image />
<h1><txp:title /></h1>
<txp:body />
</txp:article_custom></txp:variable>

<txp:if_variable name="catlist" value=""><txp:else />
<h2 class="accordion-header"><txp:category title="1" /></h2>
<div class="accordion-content"> 
<txp:variable name="catlist" />
</div>
</txp:if_variable>
</txp:category_list>

Offline

#3 2013-10-08 10:01:35

txpdevcoder
Member
Registered: 2012-06-07
Posts: 58

Re: Custom Category List

Thanks etc but that doesn’t seem to work. I am still getting a heading without any content under it. Any other thoughts?

Offline

#4 2013-10-08 11:19:52

etc
Developer
Registered: 2010-11-11
Posts: 5,393
Website GitHub

Re: Custom Category List

It works for me. Look if there is an empty <div class="accordion-content"> after these lonely headings. If so, check if there is no linebreaks inside the variable.

Offline

#5 2013-10-08 11:45:35

txpdevcoder
Member
Registered: 2012-06-07
Posts: 58

Re: Custom Category List

Ah! thanks. Such a silly problem. I was right all along, i had something similar to what you suggested but space characters and line breaks were giving the variable a value.

All sorted now. Thanks!

Offline

#6 2013-10-08 11:48:50

etc
Developer
Registered: 2010-11-11
Posts: 5,393
Website GitHub

Re: Custom Category List

It makes me wonder if if_variable shouldn’t trim its value, this is a very common issue.

Offline

#7 2013-10-08 11:55:41

txpdevcoder
Member
Registered: 2012-06-07
Posts: 58

Re: Custom Category List

It would make more sense, yes.

invisible characters should not count as a value!

Offline

#8 2013-10-08 12:04:20

etc
Developer
Registered: 2010-11-11
Posts: 5,393
Website GitHub

Re: Custom Category List

That has been extensively discussed here and elsewhere, so there must be something against it that I miss.

Offline

Board footer

Powered by FluxBB