Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-04-26 17:37:02

mattmikulla
Member
From: Nashville Tennessee
Registered: 2004-08-25
Posts: 281
Website

Assign active class to link in menu list if currently viewing article

I have a menu in the sidebar displaying all articles in a section called Features. When someone is viewing an individual article I want that article title in the sidebar menu to have a class=“active”

What would be the best way to achieve this?


Art Rogue – Fine Art Photography

Offline

#2 2010-04-26 17:51:32

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 638
Website

Re: Assign active class to link in menu list if currently viewing article

I think this will do the work:
class="<txp:if_article_id id='<txp:article_id />'>active</txp:if_article_id>"

Last edited by THE BLUE DRAGON (2010-04-26 17:51:51)

Offline

#3 2010-04-26 17:54:46

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Assign active class to link in menu list if currently viewing article

The if_article_id tag only works inside if_individual_article tags, see also this TXP Tip.

Offline

#4 2010-04-26 18:00:25

mattmikulla
Member
From: Nashville Tennessee
Registered: 2004-08-25
Posts: 281
Website

Re: Assign active class to link in menu list if currently viewing article

So if my menu is present on a Section front or category page I need to use a plugin like rvm_if_this_article?


Art Rogue – Fine Art Photography

Offline

#5 2010-04-26 18:19:50

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 638
Website

Re: Assign active class to link in menu list if currently viewing article

Els wrote:

The if_article_id tag only works inside if_individual_article tags

Are you sure about that? it’s says nothing about that in the Textbook page

and sorry there is no need for the <txp:article_id /> tag because it’s the default cool ;)

class="<txp:if_individual_article><txp:if_article_id>active</txp:if_article_id></txp:if_individual_article>"

mattmikulla wrote:

So if my menu is present on a Section front or category page I need to use a plugin like rvm_if_this_article?

Good question because it’s not individual so the code I just post will not show anything
+1
Els?

Offline

#6 2010-04-26 19:47:38

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Assign active class to link in menu list if currently viewing article

mattmikulla wrote:

So if my menu is present on a Section front or category page I need to use a plugin like rvm_if_this_article?

THE BLUE DRAGON wrote:

Good question because it’s not individual so the code I just post will not show anything
+1
Els?

No, you don’t need the plugin. In article list context you don’t want the code to show anything, do you? ;)

Offline

#7 2010-04-26 20:03:08

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 638
Website

Re: Assign active class to link in menu list if currently viewing article

He’s talking about that when you first enter to a section (page) (with or without a category),
that has for example <txp:article limit=“1”> on the left side,
and on the right side there is a list of other articles using <txp:article_custom />.
so then on the left side it will show you only the latest article (because of the limit-1),
but because it’s not individual-article-page you can’t highlight the current article in the list on the right side.

Offline

#8 2010-04-26 21:18:34

mattmikulla
Member
From: Nashville Tennessee
Registered: 2004-08-25
Posts: 281
Website

Re: Assign active class to link in menu list if currently viewing article

Yea. Not working when I use txp:article_custom.

When it’s not on an individual article there should be no class assigned.

Last edited by mattmikulla (2010-04-26 21:52:46)


Art Rogue – Fine Art Photography

Offline

#9 2010-04-27 00:29:00

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Assign active class to link in menu list if currently viewing article

mattmikulla wrote:

When it’s not on an individual article there should be no class assigned.

I don’t quite get this because that’s about the opposite of what Gil says?

He’s talking about that when you first enter to a section (page) (with or without a category),
that has for example <txp:article limit=“1”> on the left side,
and on the right side there is a list of other articles using <txp:article_custom />.
so then on the left side it will show you only the latest article (because of the limit-1),
but because it’s not individual-article-page you can’t highlight the current article in the list on the right side.

If I’m not mistaken that is exactly what Joop’s code on TXP Tips does…

Offline

#10 2010-04-27 10:09:41

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 638
Website

Re: Assign active class to link in menu list if currently viewing article

Els wrote:

I don’t quite get this because that’s about the opposite of what Gil says?

Yes Els it’s look like it’s the opposite of what I understand from he’s post, sorry.
then if you Matt don’t want it to assign a class if it’s not individual, just do not use the <txp:else /> part on that txptip code.

If I’m not mistaken that is exactly what Joop’s code on TXP Tips does…

Yea yea stupid me lol!
I for some reason totally ignored the <txp:else /> part,
that do exactly what I want!
thanks for bringing me back into focus lol ;)

But now I’m having an other problem, that the ‘else’ part only works with <txp:article_custom />
but not with the rss_suparchive plugin that allow paging, not like article-custom that don’t.
so I will just not use the ‘else’ part :/ (I must have paging for my side article-list)

Offline

Board footer

Powered by FluxBB