Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-01-07 13:19:58

lythande
Member
Registered: 2009-09-08
Posts: 185
Website

If category has article, then show category in category_list

Hej,

how I can show only categories in the category_list, if the category has articles?

The normal <txp:category> and <txp:category_list> has no function for say “only show the category in the category_list, if the category has articles”. Or have I not see this?

At moment here my code:

<txp:category_list wraptag="ul" break="" parent="kunstarbeiten" exclude="kunstarbeiten">
    <li<txp:if_category name="<txp:category />"> class="active"</txp:if_category>>
        <txp:category title="1" link="1" />
    </li>
</txp:category_list>

But this code show categorys, there is no articles…
Best regards
Lythande

Offline

#2 2018-01-07 13:32:25

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,389

Re: If category has article, then show category in category_list

<txp:category_list section="section-name" class="" wraptag="ul" break="" parent="kunstarbeiten" exclude="kunstarbeiten">

	<txp:variable name="cat-has-article"><txp:article_custom category="category-name" limit="1" /></txp:variable>

	<txp:if_variable name="cat-has-article" value="">

			<!-- nothing or code if category hasn't article -->

		<txp:else />

			<!-- code if category has article -->

	</txp:if_variable>

</txp:category_list>

Offline

#3 2018-01-07 14:17:43

lythande
Member
Registered: 2009-09-08
Posts: 185
Website

Re: If category has article, then show category in category_list

Much thanks for very quick answer! :-)

I have tried it, but with this code:

<txp:category_list wraptag="ul" break="" parent="kunstarbeiten" exclude="kunstarbeiten">
    <txp:variable name="cat-has-article"><txp:article_custom category="<txp:category_list break="" parent="kunstarbeiten" exclude="kunstarbeiten"><txp:category /></txp:category_list>" limit="1" /></txp:variable>
      <txp:if_variable name="cat-has-article" value="">
      <txp:else />
       <li<txp:if_category name="<txp:category />"> class="active"</txp:if_category>>
         <txp:category title="1" link="1" />
       </li>
    </txp:if_variable>
</txp:category_list>

I wish <txp:article_custom category="category_name" /> (the category_name) could be fill automatically, because maybe there new categories coming inside. But the code above doesnt match the one category has not articles.
And the code with <txp:article_custom category="<txp:category />" /> leave empty the category-links… (same results with <txp:category2 /> )

The articles on this one section has the code <txp:article form="kunstliste" limit="10000" /> for show the articles in difference categories and in the choosed category.

Offline

#4 2018-01-07 14:34:15

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,389

Re: If category has article, then show category in category_list

category='<txp:category />'

category with single quotes…

Offline

#5 2018-01-07 14:42:39

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,102

Re: If category has article, then show category in category_list

Sorry, can’t be of any more help than this, ATM:

Your category="<txp:category_list break="" parent="kunstarbeiten" exclude="kunstarbeiten"><txp:category /></txp:category_list>"
has to be
category='<txp:category_list break="" parent="kunstarbeiten" exclude="kunstarbeiten"><txp:category /></txp:category_list>'
(I.e. single quotes for tags inside tags. Always.)

Edit: GugUser was faster.

Last edited by uli (2018-01-07 14:43:45)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2018-01-07 14:50:25

lythande
Member
Registered: 2009-09-08
Posts: 185
Website

Re: If category has article, then show category in category_list

Much thanks your both!

The right way was this:

<txp:variable name="cat-has-article"><txp:article_custom category='<txp:category />' limit="1" /></txp:variable>

By the way: The code from uli leave the category_list empty. Maybe there is a loop, so i tried the '<txp:category />' and the result is, that the category has no article don’t show in the list.

On the idea to make a ‘xy’ instead “xy” i couldn’d coming… thanks! :-)

Offline

#7 2018-01-07 15:02:12

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,389

Re: If category has article, then show category in category_list

Tags in tags needs single quotes.

Offline

Board footer

Powered by FluxBB