Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-03-26 19:40:44

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 720
Website

How to highlight article title ... !?

What’s the most common way to get the active article title in the left sidebar (in this case with the tag txp:recent_articles) highlighted? The trouble is of course to get the title highlighted of the latest article … which is the article on the landing page! Thanks for any advice and/or showing-me-how-to’s!

Last edited by RedFox (2009-03-26 20:00:20)

Offline

#2 2009-03-26 20:09:29

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

Re: How to highlight article title ... !?

It’s not possible with recent_articles, but you can easily replace that with article_custom. Depending on your setup (is the landing page a section page? category page? you might need if_section and/or if_category as well), and assuming you are sorting by date descending, so the most recent article is the first article in the list, you could do something like this:

<txp:if_individual_article>
	<txp:article_custom>
		<txp:if_first_article><ul></txp:if_first_article>
		<li<txp:if_article_id> class="active"</txp:if_article_id>><txp:permlink><txp:title /></txp:permlink></li>
		<txp:if_last_article></ul></txp:if_last_article>
	</txp:article_custom>
<txp:else />
	<txp:article_custom>
		<txp:if_first_article><ul></txp:if_first_article>
		<li<txp:if_first_article> class="active"</txp:if_first_article>><txp:permlink><txp:title /></txp:permlink></li>
		<txp:if_last_article></ul></txp:if_last_article>
	</txp:article_custom>
</txp:if_individual_article>

Edit: note to self: don’t post code when you’re in a hurry, you will likely forget to close conditional tags and leave stray closing brackets…

Last edited by Els (2009-03-26 22:21:42)

Offline

#3 2009-03-26 20:47:36

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,201
Website

Re: How to highlight article title ... !?

Or using rvm_if_this_article

<txp:if_first_article><ul></txp:if_first_article>
<ul class="<txp:rvm_if_this_article> active</txp:rvm_if_this_article>"><txp:permlink><txp:title/></txp:permlink></li>
<txp:if_last_article></ul></txp:if_last_article>

Offline

#4 2009-03-26 20:52:29

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 720
Website

Re: How to highlight article title ... !?

Thanks Els!

I did some tweaking:

<txp:if_individual_article>
	<txp:article_custom section="home" sort="position asc">
		<txp:if_first_article><ol></txp:if_first_article>
		<li<txp:if_article_id> class="active"></txp:if_article_id><txp:permlink><txp:title /></txp:permlink></li>
		<txp:if_last_article></ol></txp:if_last_article>
	</txp:article_custom>
</txp:if_individual_article>
<txp:else />
	<txp:article_custom section="home" sort="position asc">
		<txp:if_first_article><ol></txp:if_first_article>
		<li<txp:if_first_article> class="active"></txp:if_first_article><txp:permlink><txp:title /></txp:permlink></li>
		<txp:if_last_article></ol></txp:if_last_article>
	</txp:article_custom>

You didn’t close the txp:if_individual_article btw … ;-)

And the results are > www.redfoxtestdrive.nl/txp

There’s something going on with <txp:else /> … but I can’t see what it is!

The landing page is ok … the first title gets ‘active’ … :) … but on a individual page the code isn’t working properly … :(

Last edited by RedFox (2009-03-26 21:38:08)

Offline

#5 2009-03-26 21:30:09

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 720
Website

Re: How to highlight article title ... !?

Thanks mrdale!

I did some tweaking:

<txp:article_custom section="teksten" sort="position asc">
		<txp:if_first_article><ol></txp:if_first_article>
<li class="<txp:rvm_if_this_article>active</txp:rvm_if_this_article>"><txp:permlink><txp:title/></txp:permlink></li>
<txp:if_last_article></ol></txp:if_last_article>
	</txp:article_custom>
</txp:if_individual_article>
<txp:else />
<txp:article_custom section="teksten" sort="position asc">
		<txp:if_first_article><ol></txp:if_first_article>
<li class="<txp:rvm_if_this_article>active</txp:rvm_if_this_article>"><txp:permlink><txp:title/></txp:permlink></li>
<txp:if_last_article></ol></txp:if_last_article>
	</txp:article_custom>

I changed ul in li btw … ;-)

And the results are > www.redfoxtestdrive.nl/txp/teksten

There’s something going on with <txp:else /> … but I can’t see what it is!

The landing page is not ok … the first title doesn’t get an ‘active’ … :( … and on an individual page the code isn’t working properly … there is however an ‘active’ … :)(

PS
It’s very likely that I’ve made a mess of the code … I’m only a pixel pusher … sorry in advance!

Last edited by RedFox (2009-03-26 21:39:57)

Offline

#6 2009-03-26 21:42:55

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,162
Website

Re: How to highlight article title ... !?

looks like you need to take </txp:if_individual_article> out of the middle and put it at the end. That should stop the double occurrence of the menu too.

Looking at it more closely I can’t see a different between the individual article text and the article list text (or I missed it – been a long day), so maybe you need just this:

<txp:article_custom section="teksten" sort="position asc">
	<txp:if_first_article><ol></txp:if_first_article>
		<li<txp:rvm_if_this_article> class="active"</txp:rvm_if_this_article>><txp:permlink><txp:title/></txp:permlink></li>
	<txp:if_last_article></ol></txp:if_last_article>
</txp:article_custom>

Also you can wrap the whole class="active" in txp:rvm_if_this_article to avoid having an empty class.


TXP Builders – finely-crafted code, design and txp

Offline

#7 2009-03-26 21:50:39

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,162
Website

Re: How to highlight article title ... !?

Actually, now I see a difference in Els earlier code. She’s used if_article_id for the individual article view (highlight currently shown article) and if_first_article in the article list situation/the else bit (to highlight the first article on a landing page) which got lost in your translation. Here’s her example again – the only thing she had erroneously in there was a stray closing bracket after class=“active”:

<txp:if_individual_article>
	<txp:article_custom>
		<txp:if_first_article><ul></txp:if_first_article>
		<li<txp:if_article_id> class="active"</txp:if_article_id>><txp:permlink><txp:title /></txp:permlink></li>
		<txp:if_last_article></ul></txp:if_last_article>
	</txp:article_custom>
<txp:else />
	<txp:article_custom>
		<txp:if_first_article><ul></txp:if_first_article>
		<li<txp:if_first_article> class="active"</txp:if_first_article>><txp:permlink><txp:title /></txp:permlink></li>
		<txp:if_last_article></ul></txp:if_last_article>
	</txp:article_custom>
</txp:if_individual_article>

Last edited by jakob (2009-03-26 21:51:25)


TXP Builders – finely-crafted code, design and txp

Offline

#8 2009-03-26 22:08:00

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 720
Website

Re: How to highlight article title ... !?

Thanks jakop!

With </txp:if_individual_article> at the end of the block of code now the results are as wished … :) … so everything is ok on the landing page and on the individual pages!

Tomorrow (smoke is coming out of my ears!) I will have a look at the code of mrdale because I did something wrong there too.

[edit]
However … in the code of Els there’s something not right … in the source I’m missing a > at the non active li’s!

<ol class="recent_articles">
<li class="active"><a rel="bookmark" href="http://www.redfoxtestdrive.nl/txp/stap-voor-stap">Stap voor stap</a></li>
<li<a rel="bookmark" href="http://www.redfoxtestdrive.nl/txp/1-lees-mij-eerst">Wat is Textpattern precies?</a></li>
<li<a rel="bookmark" href="http://www.redfoxtestdrive.nl/txp/hoe-ziet-textpattern-eruit">Hoe ziet Textpattern eruit?</a></li>
<li<a rel="bookmark" href="http://www.redfoxtestdrive.nl/txp/inloggen">Inloggen</a></li>
<li<a rel="bookmark" href="http://www.redfoxtestdrive.nl/txp/4-de-interface-encore">Hoe navigeer je in Textpattern?</a></li>
</ol>

Last edited by RedFox (2009-03-26 22:39:02)

Offline

#9 2009-03-26 22:32:17

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

Re: How to highlight article title ... !?

jakob wrote:

the only thing she had erroneously in there was a stray closing bracket after class=“active”

RedFox wrote:

You didn’t close the txp:if_individual_article btw … ;-)

Yeah sorry, I was in a hurry…

Tomorrow (smoke is coming out of my ears!) I will have a look at the code of mrdale because I did something wrong there too.

You didn’t open the txp:if_individual_article ;-)
And, just like in my code, the closing tag should be at the end of the code; also you can’t use rvm_if_this_article outside an individual article context.

But why use a plugin when a TXP tag exists (if_article_id)?

Offline

#10 2009-03-26 22:40:58

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 720
Website

Re: How to highlight article title ... !?

Els, please look at the post above your last … about the missing >>

Offline

Board footer

Powered by FluxBB