Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-08-09 02:22:18

Lupulus
New Member
Registered: 2009-08-09
Posts: 4

section_list active_class

Hello everyone,

I’ve just installed Textpattern and now want to code my own design. I have a problem with the menu highlighting of the active section though: First of all, I tried this textpattern code:

<txp:section_list active_class="active" break="li" include_default="0" sort="name desc" wraptag="ul" />

The active_class didn’t work so I tried this and it worked:

<txp:section_list include_default="0" sort="name desc" wraptag="ul" break=""> <li<txp:if_section name='<txp:section />'> class="active"</txp:if_section> <txp:section link="1" title="1" /> </li> </txp:section_list>

But I still have a problem: My standard section is the blog, which has the section name “blog”. The point is, “Blog” isn’t highlighted in my menu when I haven’t clicked at it. http://timwoelfle.de/ and http://timwoelfle.de/blog/ show exactly the same things, but only the second URL is highlighted correctly. How can I fix that? This also affects the page title.

Thank you, I’m really having fun with Textpattern so far, but this problem really drives me crazy.

Lupulus

Offline

#2 2009-08-09 07:14:02

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: section_list active_class

Surprising your first code sample does not work as it should. I think in your second example you need include_default like so:

<txp:section_list sections=",blog,about" wraptag="ul" break="" active_class="active" default_title="Blog" include_default="1" />

Offline

#3 2009-08-09 11:54:13

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

Re: section_list active_class

Lupulus wrote:

<txp:section_list active_class="active" break="li" include_default="0" sort="name desc" wraptag="ul" />

The active_class didn’t work

I’ve seen this happening before, and it was caused by using capitals in section names (never do that!). Could that be your problem?

In this code:

<txp:section_list include_default="0" sort="name desc" wraptag="ul" break="">
	<li<txp:if_section name='<txp:section />'> class="active"</txp:if_section>
		<txp:section link="1" title="1" />
	</li>
</txp:section_list>

you are missing a > to close the <li tag:

<txp:section_list include_default="0" sort="name desc" wraptag="ul" break="">
	<li<txp:if_section name='<txp:section />'> class="active"</txp:if_section>>
		<txp:section link="1" title="1" />
	</li>
</txp:section_list>

The point is, “Blog” isn’t highlighted in my menu when I haven’t clicked at it.

Expected behaviour I’d say ;) But I’m guessing you want it to be highlighted on your front page too, right? In that case, try this:

<ul class="section_list">
	<li<txp:if_section name=",blog"> class="active"</txp:if_section>>
		<txp:section name="blog" link="1" title="1" />
	</li>
	<txp:section_list exclude="blog" sort="name desc" break="">
		<li<txp:if_section name='<txp:section />'> class="active"</txp:if_section>>
			<txp:section link="1" title="1" />
		</li>
	</txp:section_list>
</ul>

Last edited by els (2009-08-09 11:57:20)

Offline

#4 2009-08-09 14:29:56

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: section_list active_class

Nice code Els – as always! I think the code I posted should work too – Lupulus, would you mind posting back to let us know if either example works? Quite curious….!

Offline

#5 2009-08-09 15:02:59

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

Re: section_list active_class

jstubbs wrote:

I think the code I posted should work too

Wouldn’t that show ‘Blog’ twice in the menu?

Offline

#6 2009-08-09 15:30:59

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: section_list active_class

Maybe so – should have thought of that before posting – I just copied one of my site menus and then added “blog” as per Lupulus’ requirements.

<txp:section_list sections=",about" wraptag="ul" break="" active_class="active" default_title="Blog" include_default="1" />

That should do it. Less code ;-)

Offline

#7 2009-08-09 15:44:13

Lupulus
New Member
Registered: 2009-08-09
Posts: 4

Re: section_list active_class

I’ve seen this happening before, and it was caused by using capitals in section names (never do that!). Could that be your problem?

No, I only have two sections called “blog” and “about”. No capitals at all.

Expected behaviour I’d say ;) But I’m guessing you want it to be highlighted on your front page too, right? In that case, try this:

Thank you, your code worked! Nice, but still a little confusing. Wasn’t that a problem that lots of people face? I mean, lot’s of people want to have their blog be shown at the main page. Never mind… Another solution I was thinking of is just redirecting timwoelfle.de to timwoelfle.de/blog – How could this be done in the Txp index.php ? I’d actually prefer this solution, because the page title would also be correct then. But first of, thanks for your code!

Offline

#8 2009-08-09 15:48:02

Lupulus
New Member
Registered: 2009-08-09
Posts: 4

Re: section_list active_class

Maybe so – should have thought of that before posting – I just copied one of my site menus and then added “blog” as per Lupulus’ requirements.

Yeah, “Blog” appeared two times with your first solution.

That should do it. Less code ;-)

Cool, thanks! This works quite fine. But it still has a problem: “Blog” isn’t highlighted anymore when I select an entry or go to “http://timwoelfle.de/blog” directly. Too bad :/

Offline

#9 2009-08-09 16:11:16

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: section_list active_class

Glad it worked! Not sure why you see an error – looks fine to me. I see this in both “timwoelfle.de” AND “timwoelfle.de/blog”:

<ul class="section_list">
	<li class="active">
		<a href="http://timwoelfle.de/blog/">Blog</a>
	</li>
		<li>
			<a href="http://timwoelfle.de/about/">Über mich</a>
		</li>
</ul>

Offline

#10 2009-08-09 16:12:01

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: section_list active_class

Same in “timwoelfle.de/2009/07/29/newsletter-01”….??

Offline

#11 2009-08-09 16:21:13

Lupulus
New Member
Registered: 2009-08-09
Posts: 4

Re: section_list active_class

Yeah, it works because I’m using Els code right now ;) The only thing that is still a little weird though is the change of the page title.

Offline

#12 2009-08-09 16:39:43

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: section_list active_class

Not sure what your setup is, but if you only have two sections – blog and about – plus default, then if you set blog to frontpage:yes in the sections tab you should only need this:

<txp:section_list sections=",blog,about" wraptag="ul" break="li" active_class="active" />

The only downside is that your Blog link won’t be active on the frontpage.

As an alternative (not sure you need anything more than Els’ code, but its always nice to see another method) you could try something like this:

<ul>
<li><a href="<txp:site_url />blog" <txp:if_section name=",blog">class="active" </txp:if_section>>Blog</a></li>
<li><a href="<txp:site_url />about" <txp:if_section name="about">class="active" </txp:if_section>>About</a></li>
</ul>

Note the ,blog in the if_section_name attribute. That turns on the active state for both default and blog.

Offline

Board footer

Powered by FluxBB