Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2009-04-19 16:36:36

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [howto] static category urls

colak wrote:

but every time the urls returned were context sensitive

I tried it on my test site. The tag used is <txp:category_list wraptag="ul" break="li" /> and it returns /category/yourcategory links from everywhere…

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.

Edit again: Yay, found it! This code returns context insensitive links:

<txp:category_list wraptag="ul" break="li">
<txp:category title="1" link="1" section="default" />
</txp:category_list>

Advantages over your example:

  1. You can exclude categories
  2. No need for the article_custom/if_different way, which I assume needs more queries

Last edited by Els (2009-05-31 21:11:10)

Offline

#12 2009-04-19 17:05:24

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,325
Website

Re: [howto] static category urls

Yep, that works!!! The txp tag God has done it again! So to appropriate your code again the final thing would be:

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

> Edit Maybe I spoke too soon:( for some reason the above code doesn’t work as it generates empty lis

ie the menu looks something like

<ul id="categorylist" class="categorylist" >
<li><a href="#">Home</a></li>
<li><a href="#">C1</a></li>
<li></li>
<li><a href="#">C2</a></li>
<li></li>
<li><a href="#">C3</a></li>
<li></li>
...
</ul>

Last edited by colak (2009-04-19 17:38:18)


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

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

Els
Admin
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: 7,325
Website

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 | LABS | State Machines | Respbublika! | NeMe @ github

Offline

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

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,325
Website

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 | LABS | State Machines | Respbublika! | NeMe @ github

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,781
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: 3,522
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

Board footer

Powered by FluxBB