Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-10-20 21:57:07
- Nell
- Member
- From: Mexico City, Mexico
- Registered: 2005-06-21
- Posts: 48
Showing the current category in a list
I’ve had this problem twice in different sites and I’m still not sure how to solve it.
I want to add a class to my navigation list that highlights the category of the article you are looking at. I could make it work with the category_list tag, but the category list uses messy urls and I’d rather have clean urls, even if I have to type them myself.
I couldn’t make it work with if_category. Is this possible? Am I doing something wrong?
Here’s an example of the way I tried to do it. My article is called services, and it has a category with the same name.
<li><a href="services" <txp:if_category name="services">class="selected"</txp:if_category>>Services</a></li>
I guess I could do this with the article id instead of the categories (i.e., add the class selected if you are in article number 6), is this possible?
Hope I was clear. Thank you!
Offline
#2 2006-10-20 22:14:12
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Showing the current category in a list
<txp:if_category>
looks for the category in the URL, so it only works with category lists. You have to use <txp:if_article_category>
, but you’ll have to upgrade to 4.0.4 to be able to use that tag outside an article form.
Offline
#3 2006-10-20 22:16:42
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: Showing the current category in a list
If you are highlghting an individual article, if_article_category would be sensitive the article category rather than the article list search category that if_category looks at.
Offline
#4 2006-10-20 22:21:35
- Nell
- Member
- From: Mexico City, Mexico
- Registered: 2005-06-21
- Posts: 48
Re: Showing the current category in a list
Yes, it’s an individual article.
I tried using if_article_category, but I get a tag context error:
tag_error <txp:if_article_category name="services"> -> Textpattern Notice: error_article_context on line 1821
By the way, I also tried it with glx_hl_current, which supposedly highlights individual articles, but I couldn’t make it work.
Offline
#5 2006-10-20 22:26:25
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Showing the current category in a list
Are you using 4.0.4? Because I just tried to use this tag on the page template and it worked. But it is not possible to do this in 4.0.3.
Offline
#6 2006-10-20 22:31:18
- Nell
- Member
- From: Mexico City, Mexico
- Registered: 2005-06-21
- Posts: 48
Re: Showing the current category in a list
Yes, it’s 4.0.4, it’s a fresh install :)
I’m using it in a form, but I pasted the form content in the page template and I’m still getting the error.
Offline
#7 2006-10-20 22:41:48
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Showing the current category in a list
Ah, I think I found it. See if this works:
<li><a href="services" <txp:if_individual_article><txp:if_article_category name="services">class="selected"</txp:if_article_category></txp:if_individual_article>>Services</a></li>
Offline
#8 2006-10-20 22:48:23
- Nell
- Member
- From: Mexico City, Mexico
- Registered: 2005-06-21
- Posts: 48
Re: Showing the current category in a list
Wah, I’m still getting the error.
Could it have anything to do with the article tag in the page? I’m using this:
<txp:article form="contenido" limit="1" status="sticky" />
Thank you so much for all your help!
Offline
#9 2006-10-20 22:56:19
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Showing the current category in a list
I swear it’s working for me. Without the if_individual_article tag I get the same error, but as soon as I add it, it starts working.
The only way to find out if it’s the sticky status that’s causing this, is to change the status temporarily and see if it makes a difference…
Offline
#10 2006-10-20 23:05:01
- Nell
- Member
- From: Mexico City, Mexico
- Registered: 2005-06-21
- Posts: 48
Re: Showing the current category in a list
Guess what, that was it :) the highlighting works perfectly now.
Now I must see if it won’t affect to use live articles instead of stickies.
Thank you for all your help!
Thanks too, rsilletti!
Offline