Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
How to omit empty categories in list?
I’m using txp:category_list to list my categories — but I would like to make such a list, with empty categories omitted. Is there a way?
J.E.B.
Offline
Re: How to omit empty categories in list?
Yes. You could use variables and article_custom to check if there is articles assigned to the category. Small example:
<txp:category_list>
<!--
Get the articles (if any) using article_custom
and assign the results to a variable named "has_articles"
-->
<txp:variable name="has_articles"><txp:article_custom category='<txp:category />' limit="1">true</txp:article_custom></txp:variable>
<!--
Now check if there is anything
inside the "has_articles" variable
-->
<txp:if_variable name="has_articles" value="">
<txp:else />
<!--
If there is, we have an article,
and we should show the category
-->
<txp:category title="1" link="1" />
</txp:if_variable>
</txp:category_list>
See:
Last edited by Gocom (2011-02-04 08:36:57)
Offline
Re: How to omit empty categories in list?
should work like this
<txp:category_list categories=“category name(s) to display”> … your other code … </txp:category_list>
A hole turned upside down is a dome, when there’s also gravity.
Offline
Re: How to omit empty categories in list?
thx Gocom.
works fine for me, cause i also need the empty categories, for some other stuff.
so this was perfect, plus the list is fully automated and nobody has to work in the form.
Offline
Re: How to omit empty categories in list?
gocom, this is great! as simple as possible, with good comments, one could not hope for more ;-)
Offline
Offline
Re: How to omit empty categories in list?
{}
||
____||_____
{~ ~ ~ ~ ~ ~}
{ ~ ~ ~ ~ ~ }
{___________}
small, but from the bottom of my heart.
Offline
Pages: 1