Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-02-04 02:21:06

jonathanbrickman0000
New Member
From: Topeka, Kansas, USA
Registered: 2011-01-22
Posts: 6
Website

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

#2 2011-02-04 08:35:36

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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

#3 2011-02-05 22:45:34

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 689
Website Mastodon

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

#4 2011-02-16 18:22:05

jens31
Plugin Author
From: munich / dtschermani
Registered: 2008-08-25
Posts: 183
Website

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

#5 2011-04-07 21:17:39

funtoosh
Member
From: Münster, Germany
Registered: 2006-10-09
Posts: 153
Website

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

#6 2011-04-08 00:05:02

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: How to omit empty categories in list?

funtoosh wrote:

gocom, this is great! as simple as possible, with good comments, one could not hope for more ;-)

Thanks :-) I wish it came with cake.

Offline

#7 2011-04-08 00:30:14

funtoosh
Member
From: Münster, Germany
Registered: 2006-10-09
Posts: 153
Website

Re: How to omit empty categories in list?

      {}
      ||
  ____||_____
 {~ ~ ~ ~ ~ ~}
 { ~ ~ ~ ~ ~ }
 {___________}

small, but from the bottom of my heart.

Offline

Board footer

Powered by FluxBB