Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2009-04-19 19:12:15

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [howto] static category urls

I think that is because it puts <li>s also around the – not displayed – empty categories, because you used break="li" in the category_list tag. What happens if you change that to break="" and move the <li> here: <li><txp:category title="1" link="1" section="default" /></li>, like in my example on TXP Tips?

Offline

#14 2009-04-20 06:17:59

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,749
Website GitHub Twitter

Re: [howto] static category urls

That did it!!! Final code:

<ul id="categorylist" class="list">
<li><a href="<txp:site_url />">Home</a></li>
<txp:category_list break="" exclude="somecategory,someothercategory">
<txp:variable name="hasarticles" value='<txp:article_custom category=''<txp:category />'' limit="1" />' />
<txp:if_variable name="hasarticles" value="">
<txp:else />
<li><txp:category title="1" link="1" section="default" /></li>
</txp:category_list>
</txp:if_variable>
</ul>

All kudos to Els!


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#15 2009-04-21 15:47:25

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,749
Website GitHub Twitter

Re: [howto] static category urls

Els wrote:

Edit: ah, now I see what’s happening: when used as a single tag it always returns /category/yourcategory links, but when used as a container tag it’s context sensitive… I find that a very strange behaviour.

A bug or a feature?


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#16 2009-08-04 10:18:03

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 858
Website

Re: [howto] static category urls

Is it possible to use the txp:variable to check for empty categories just using txp:category_list without using txp:article_custom?

The reason being is that I still would like to use the “active_class” which comes with txp:category_list :)

Thanks

Offline

#17 2009-08-04 11:52:27

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: [howto] static category urls

tye wrote:

Is it possible to use the txp:variable to check for empty categories just using txp:category_list without using txp:article_custom?

Yes, using this code from Els referenced at the start of this thread.


Code is topiary

Offline

#18 2009-08-05 02:11:52

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 858
Website

Re: [howto] static category urls

Thanks for all the answers to all my posts :)

nm… I have read this article on txp:variable and read all of the great code supplied by els… but I guess I’m just stoopid, slow or both.

I understand that the below sets a variable which can be used over and over, or can be used in a conditional statement

<txp:variable name="hasarticles" value='<txp:article_custom category=''<txp:category />'' limit="1" />' />

What I am not understanding is how it checks to see if there is articles in that category :(

It works (thanks) – but I’m just trying to understand it better so I can use it more as it does look really powerful

Offline

#19 2009-08-05 07:04:45

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,178
Website

Re: [howto] static category urls

What I am not understanding is how it checks to see if there is articles in that category :(

This bit <txp:article_custom category='<txp:category />' limit="1" /> in the value attribute would normally output a list of articles in the currently set category, stopping after the first one. If there are no articles in that category it outputs nothing. This value is saved into the variable hasarticles. That means that if there is output, the variable hasarticles will contain something (for our purposes it doesn’t matter what it actually contains, just whether it contains something).

The code then test to see if the variable is empty and if not empty does your code:

<txp:if_variable name="hasarticles" value="">
  <!-- no articles -->
<txp:else />
  <!-- has articles -->
</txp:if_variable>

TXP Builders – finely-crafted code, design and txp

Offline

#20 2009-08-05 08:41:17

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 858
Website

Re: [howto] static category urls

Ah – it seems so easy when you put it like that, of course, I see what is happening now :)

Thanks

Offline

#21 2009-08-06 07:02:56

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 858
Website

Re: [howto] static category urls

txp:variable is superb… thanks team :)

Offline

#22 2019-06-01 13:16:38

phildyer
New Member
From: Logres
Registered: 2019-05-15
Posts: 1
Website

Re: [howto] static category urls

I am not sure how relevant this post is now, considering the age, but I found it in a search and it was what I was looking for – so here goes – my first contribution to this forum.

A great little bit of code. I love the exclude as I have made some categories for internal use only.

However it did flag up a couple of errors at first due to the fact that </txp:category_list> should be below </txp:if_variable>


A Textpattern Tinkerer

Offline

Board footer

Powered by FluxBB