Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#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
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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
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
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
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
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
Re: [howto] static category urls
txp:variable is superb… thanks team :)
Offline
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