Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-04-19 21:01:21

woy
Member
Registered: 2009-04-08
Posts: 18

Highlight category when an sticky article is displayed

I had added this issue to my last thread but I think it has gone lost in the mess I created.

I’v marked my “news” section as “on front page” to display it when opening the website. My main navigation consist of a section list and I highlight the selected one using

<li<txp:if_section name='<txp:section/>'> class="active"<txp:else/> </txp:if_section>.

Is there a solution to declare the section “news” as selected although I’ve not navigated to it?

And intertwined with that:

Currently I put my articles in place using the following tag structure:

<txp:if_individual_article> <txp:article form="standard" /> <txp:else /> <txp:article status="sticky" form="standard" category='<txp:category>'/> </txp:if_individual_article> 

I’m using sticky articles as landing pages for the sections. These articles have also a category assigned and I would like to have my category highlighted when I navigate to a section.

Can I achieve this without hard coding the navigation in my templates?

Thanks in advance,

Sebastian

Offline

#2 2009-04-19 22:38:28

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Highlight category when an sticky article is displayed

For the first example Sebastian, I’m assuming you are hard-coding the list. If that is the case then for the news link you could use:-

<li<txp:if_section name=",default"> class="active" </txp:if_section>

Also note that I don’t think you need the <txp:else /> tag at all as, if the check fails there will be no output from the tag. Shorten your code a little.

No help on your second example at the moment. Still thinking about it.


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#3 2009-04-20 21:10:37

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

Re: Highlight category when an sticky article is displayed

Sebastian, sorry I overlooked your last question in the other thread. Just to check if I understand what you want to do: on every section landing page you are displaying one sticky article, and you want this code:

<li<txp:if_category name='<txp:category/>'> class="active"<txp:else />
<txp:if_individual_article><txp:if_article_category name='<txp:category />'> class="active"
</txp:if_article_category></txp:if_individual_article></txp:if_category>>
<txp:category link="1" title="1" /></li>

to highlight also the sticky article’s category when on a section landing page?

And just a note: in this code

<txp:if_individual_article> <txp:article form="standard" /> <txp:else /> <txp:article status="sticky" form="standard" category='<txp:category>'/> </txp:if_individual_article> 

you don’t need the category='<txp:category />'. In fact <txp:article /> doesn’t even take the category attribute. It is not needed because the tag is context sensitive and therefore on a category page it will display only articles from that category. What this code does on a section landing page, is display the sticky article(s) in that section.

Last edited by els (2009-04-20 21:17:36)

Offline

#4 2009-04-20 22:16:53

woy
Member
Registered: 2009-04-08
Posts: 18

Re: Highlight category when an sticky article is displayed

@stuart

Thanks for the tip. I left out the superfluous <txp:else />

My section-list is generated using

<txp:section_list break="" wraptag="ul" form="center_col_nav_build" class="center_col_nav" exclude="impressum, agb, postit"/>

Adding a second conditional using ",default" highlights all links in the list.

Did I get you wrong?

Offline

#5 2009-04-20 22:23:04

woy
Member
Registered: 2009-04-08
Posts: 18

Re: Highlight category when an sticky article is displayed

@els

Thank you for the hint on <txp:article />. I removed it.

Yes, thats exactly what I want to achieve. I would like to get the category of the sticky-article on the section landing page to be highlighted when navigating to the section page.

Offline

#6 2009-04-20 22:28:09

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

Re: Highlight category when an sticky article is displayed

What you could do with your section list is this:

<ul class="center_col_nav">
	<txp:section_list break="" form="center_col_nav_build_news" sections="news" />
	<txp:section_list break="" form="center_col_nav_build" exclude="news,impressum,agb,postit" />
</ul>

And in your form ‘center_col_nav_build_news’ use this:

<txp:if_section name=",news"> class="active"</txp:if_section>

Offline

#7 2009-04-20 22:41:55

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

Re: Highlight category when an sticky article is displayed

woy wrote:

Yes, thats exactly what I want to achieve. I would like to get the category of the sticky-article on the section landing page to be highlighted when navigating to the section page.

OK, I put together something that I think might work, but I didn’t test it – because I don’t have the same setup as yours anywhere, and creating it just to test this would take too much time… ;)

Your form ‘nav_build’ would need to be expanded a little, I added tabs and comments to try and make clear what it does (or what I expect it to do…). You will probably want to remove these, because it already is a whole lot of code to put inside a humble <li> tag ;)

<li<txp:if_individual_article>
<!-- if we are on an individual article page -->
	<txp:if_article_category name='<txp:category />'>
	<!-- if the article's category matches this category in the list, highlight it -->
		 class="active"
	</txp:if_article_category>
<txp:else />
<!-- if we are on an article list page -->
	<txp:if_category name='<txp:category />'>
	<!-- if we are on a category list page, and the currently viewed category matches this category in the list, highlight it -->
		 class="active"
	<txp:else />
		<txp:if_section>
		<!-- if we are on a section list page -->
			<txp:variable name="sticky_article_category" value='<txp:article status="sticky" limit="1"><txp:category1 /></txp:article>' />
			<!-- set the variable's value to the sticky article's category1 -->
			<txp:if_variable name="sticky_article_category" value='<txp:category />'>
			<!-- if the sticky article's category1 matches this category in the list, highlight it -->
				 class="active"
			</txp:if_variable>
		</txp:if_section>
	</txp:if_category>
</txp:if_individual_article>>
	<txp:category link="1" title="1" />
</li>

Last edited by els (2009-04-20 22:43:53)

Offline

#8 2009-04-22 19:25:12

woy
Member
Registered: 2009-04-08
Posts: 18

Re: Highlight category when an sticky article is displayed

Wow Els, that’s just insane. ;) Works perfectly without any adjustments. Thank you.

Sorry for bothering you again, but do you have an idea for a solution for the first issue?

Offline

#9 2009-04-22 20:33:24

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

Re: Highlight category when an sticky article is displayed

woy wrote:

Wow Els, that’s just insane. ;) Works perfectly without any adjustments.

Phew… I’m glad to hear that :)

Sorry for bothering you again, but do you have an idea for a solution for the first issue?

Can’t think of anything better than this.

Offline

Board footer

Powered by FluxBB