Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
if_category in a single article contexte
Hi
I have a navigation using categories and want to test what category i am to add a css style.
the code is :
<ul id="menu1">
<li <txp:if_section name="">id="active"</txp:if_section>><a href="/">Accueil</a></li>
<txp:category_list parent="fra" exclude="fra, contact" section="fr" sort="id asc" children="0" break="">
<li <txp:if_category name='<txp:category />'>id="active"</txp:if_category>><txp:category title="1" link="1" section="fr"/>
<txp:category_list parent='<txp:category />' exclude='<txp:category />' section="fr" sort="id asc" children="0" break="">
<txp:if_first_category><ul></txp:if_first_category>
<li><txp:category title="1" link="1" section="fr"/></li>
<txp:if_last_category></ul></txp:if_last_category>
</txp:category_list>
</li>
</txp:category_list>
<li><a href="#">Forum</a></li>
<li><txp:category title="1" link="1" section="fr" name="contact" /></li>
</ul>
When i am on an article list it works right, but when i view a sigle article the txp:if_category fails to find the category, then i modified the code for an individual article view like this:
<ul id="menu1">
<li><a href="/">Accueil</a></li>
<txp:category_list parent="fra" exclude="fra, contact" section="fr" sort="id asc" children="0" break="">
<li <txp:if_category name='<txp:smd_parent level="-1" catnum="1" />'>id="active"</txp:if_category>><txp:category title="1" link="1" section="fr"/>
<txp:category_list parent='<txp:category />' exclude='<txp:category />' section="fr" sort="id asc" children="0" break="">
<txp:if_first_category><ul></txp:if_first_category>
<li><txp:category title="1" link="1" section="fr"/></li>
<txp:if_last_category></ul></txp:if_last_category>
</txp:category_list>
</li>
</txp:category_list>
<li><a href="#">Forum</a></li>
<li><txp:category title="1" link="1" section="fr" name="contact" /></li>
</ul>
But it s not working, the ‘<txp:smd_parent level=”-1” catnum=“1” />’ gives the right information but the txp:if_category fail to match the right category
I am not sure how txp:if_category works under a txp:category_list! is this a bug?
Cheers
Offline
#2 2010-03-02 17:22:03
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if_category in a single article contexte
Change this
<txp:if_category name='<txp:category />'>id="active"</txp:if_category>
into something like this
<txp:if_individual_article>
<txp:if_article_category name='<txp:category />'>
id="active"
</txp:if_article_category>
<txp:else />
<txp:if_category name='<txp:category />'>
id="active"
</txp:if_category>
</txp:if_individual_article>
Offline
Re: if_category in a single article contexte
Hi Els
Thanks for your respons, i tried that, but the problem is my navigation has a 2 category level + article, then to match all the cases I must use smd_if cause i need to compare the parent article category and sometime the parent category to match my need, then the code now look like this:
<txp:if_individual_article>
<txp:if_article_category name="cat1_1,cat1_2,cat2_1,cat2_2">
<txp:smd_if field="parent:CAT1" operator="eq" value='<txp:category />'>
id="active"
</txp:smd_if>
<txp:else />
<txp:if_article_category name='<txp:category />'>
id="active"
</txp:if_article_category>
</txp:if_article_category>
<txp:else />
<txp:if_category name="cat1_1,cat1_2,cat2_1,cat2_2">
<txp:smd_if field="parent:LVL2" operator="eq" value='<txp:category />'>
id="active"
</txp:smd_if>
<txp:else />
<txp:if_category name='<txp:category />'>
id="active"
</txp:if_category>
</txp:if_individual_article>
And the cat nav structure is like this:
- cat1
- cat1_1
- cat1_2
- cat2
- cat2_1
- cat2_2
- cat 3
- cat4
Last edited by Dragondz (2010-03-03 08:07:19)
Offline
#4 2010-03-03 17:54:55
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if_category in a single article contexte
Dragondz wrote:
the code now look like this:
Looks good to me, does it do what you want?
Offline