Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Insert class into li tags
I’m using the following to insert a class into “li” tags depending on the section. It works fine for all sections except “article.” Any ideas?
<li<txp:if_section name='<txp:section />'> class="current_page_item"</txp:if_section>>
<txp:section title="1" link="1" />
</li>
Mark
Offline
#2 2010-05-06 21:13:53
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Insert class into li tags
mwr wrote:
It works fine for all sections except “article.”
Do you mean it doesn’t work on individual article pages? On article list pages it should work in every section. To make it work on individual article pages as well, use something like this:
<li<txp:if_individual_article><txp:if_article_section name='<txp:section />'> class="current_page_item"</txp:if_article_section><txp:else /><txp:if_section name='<txp:section />'> class="current_page_item"</txp:if_section></txp:if_individual_article>>
<txp:section title="1" link="1" />
</li>
Offline
Re: Insert class into li tags
I actually have a section called article, which displays the articles in a blog. The other sections display short articles on various other topics.
When I view the source, the class is present if I’m in a section other than article — e.g. example.com/text. It’s not there if I’m in article — i.e. example.com/article.
This might give you a better idea:
<ul class="group" id="example-one">
<txp:section_list sections="article,games,internet,text,graphics,utilities,organizers,audiovideo,ipod,etcetera" break="">
<li<txp:if_section name='<txp:section />'> class="current_page_item"</txp:if_section>>
<txp:section title="1" link="1" />
</li>
</txp:section_list>
</ul>
Mark
Offline
Offline
Re: Insert class into li tags
After a good night’s sleep, I figured out that the problem was related to the article section being associated with a different page from the others, which led to other complications . . . In the end, glx_if came to the rescue.
Mark
Offline
Re: Insert class into li tags
mwr wrote:
glx_if came to the rescue.
glx_if still works after all this time?! Wow… perhaps I should put some of that voodoo into smd_if :-)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#7 2010-05-07 16:18:31
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Insert class into li tags
Bloke wrote:
glx_if still works after all this time?! Wow… perhaps I should put some of that voodoo into smd_if :-)
As far as I know everything glx_if does can be done with native Txp tags now.
Offline
Re: Insert class into li tags
I find that glx_if_frontpage comes in handy. I first started using it when an advertiser insisted that an ad show only on the front page. Is there a better option?
Mark
Offline
#9 2010-05-08 14:17:03
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Insert class into li tags
That depends on how you define ‘better’ ;) glx_if is quicker, you’d need more than one native txp conditional tag to achieve the same thing.
Offline
Pages: 1