Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-01-31 02:12:19

flamenco
Member
Registered: 2009-01-07
Posts: 18

active_class not active on first item in section_list?

Hi!
I’m new, and setting up a simple menu bar (of links) on my site. I used section_list to get my links, and I wanted to use active_class to style the current link with CSS.

This seems to work great on all but the first section_list item. To put it another way, as I go to each link, each one gets…

class=“active”

… on it, just as I’d hoped. But if I click on the first section_list item link, there’s no class on it. All the other sections work fine.

Any thoughts? Might this be by design?

Thanks!

Offline

#2 2009-01-31 11:55:54

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

Re: active_class not active on first item in section_list?

It would help if you posted the code you are using :)

Offline

#3 2009-01-31 18:55:19

flamenco
Member
Registered: 2009-01-07
Posts: 18

Re: active_class not active on first item in section_list?

Els,
See, you have the magic touch… I seem to have fixed it, yet revealed another mystery, albeit trivial.

Here’s my call:
<txp:section_list active_class=“active” break=“li” exclude=“articles” />

As you can see, I have excluded Articles. My non-classed page was, you guessed it, under Articles. I changed its Section, and the class started working with it immediately, so mystery solved! Thanks!!!

Remaining mystery… I wonder why that content showed up in the menu at all before, since it was an “Article”, and my call supposedly excluded them. :) My other items under Articles were excluded properly. In case it matters, I did just upgrade to the 4.08 version.

Thanks as always!

Offline

#4 2009-01-31 21:39:43

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

Re: active_class not active on first item in section_list?

I’m not sure I understand you, but if you are saying that an article in section ‘articles’ showed up on another section’s page, then my guess is that it was called from that page with an article_custom tag…

Offline

#5 2009-01-31 22:19:24

flamenco
Member
Registered: 2009-01-07
Posts: 18

Re: active_class not active on first item in section_list?

Els,
Sorry to be confusing! No, it’s not showing up on a different page at all. It is possible that I’m going about this entirely the wrong way. I’m just putting together a tiny little site, at a moron level. :) This allows me to figure out how a CMS works, and figure out its templating. I want 5 menu items, and each points to a static page. No blogging.

The menu would be like this:

contact form
Home
page1
page2
page3

That’s 5 little pages. Thinking about the TXP system, it seemed that a way to do this is to make 5 sections, write 5 “contents”, and assign each to a section. For practice, I also wrote a couple of “contents” and called them Articles, and I also added code to the call to exclude “Articles” from the menu. Then I got the form plugin, and assigned that to the Contact page.

So far so good, all my desired items are in the menu from the section_list call. Then I wanted to style the “active” menu item, so I added the class stuff. In other words, when a menu item is clicked, it gets the “active” class so I can highlight it with CSS. A very very typical thing to do on a site.

The “active” class worked for clicking every menu item except the Contact Form page. I finally realized that the Contact Form content was assigned to “Articles”. I changed that to be in the “Content” section, and then the class started working for that menu item, too.

What I don’t understand is why the Contact Form page would appear in the menu at all when it was assigned to “Articles”; I thought I marked the call to exclude Articles.

Does that make more sense? Thanks.

Last edited by flamenco (2009-01-31 22:21:25)

Offline

#6 2009-02-01 00:58:27

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

Re: active_class not active on first item in section_list?

flamenco wrote:

What I don’t understand is why the Contact Form page would appear in the menu at all when it was assigned to “Articles”; I thought I marked the call to exclude Articles.

What you display with the section_list tag is sections, not pages. Each section can have it’s own page, but you can also have only one page and assign that to all sections. So if this was your menu – generated by the section_list tag -

contact form
Home
page1
page2
page3

you must have (had) a section ‘contact form’, using your contact form page, as well, otherwise it could never have been displayed in the menu.

I’m still not sure why the active class wouldn’t work, what was the URL of the page this menu item linked to?

Offline

#7 2009-02-01 01:52:19

flamenco
Member
Registered: 2009-01-07
Posts: 18

Re: active_class not active on first item in section_list?

Wow. This is really complicated for such a simple idea. Either I can’t follow documentation directions (probably the case), or it actually is difficult to set up a little site with just 5 or 6 static pages and get them into a menu using my own really simple template. I honestly can’t find an easy way to do that, and none of the examples I look at do this simple thing. I give myself an official grade of F.

It’s probably just me. Thanks for the help. Rather than bugging you more, I think I’ll just go back to the book and see if I can follow one of those examples, and if that doesn’t work, well, I’ll just move on to another script.

Thanks anyway, Dave

Offline

#8 2009-02-01 02:15:54

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

Re: active_class not active on first item in section_list?

flamenco wrote:

and if that doesn’t work, well, I’ll just move on to another script.

Don’t do that, I probably just made it sound far more difficult than it is… ;) Textpattern is great for complicated sites as well as for simple static sites like your’s. I understand your initial problem was solved, so by all means continue and when you have questions just post them here :)

Offline

#9 2009-02-01 02:36:24

flamenco
Member
Registered: 2009-01-07
Posts: 18

Re: active_class not active on first item in section_list?

I do very much appreciate your help! It’s really funny, after having built dozens of systems with other CMS’s, this one looks so good, but I just can’t figure it out to save my life. What I need is TXP for dummies. [template is a page, content is not a page, it’s a, uh, I don’t know, a “content” thingie??? ]

To answer your question, yes, I made a Contact Page, er Contact content (?). Then I made a Section called Contact, and I assigned the Contact Content to the Contact Section. I did the same thing with all my other pages. I didn’t want any of the 5 “contents” to show up on the same webpage. Lastly I made the section_list call to get the menu to show up with each doc in its own Section. I’m sure that’s wrong, but that’s the only way I could get my Contact page (and other pages) to show up in my menu.

As I’m pretty certain that I’m following the wrong premise, and I’m way off-topic now, I’ll have to trash the whole thing and start again.

I’ll try one more question. If you had a bunch of static pages, and wanted them to simply show up in a menu, how would you approach that? With other systems, I’ve been able to make one call from a template that shows the whole menu of published pages. Maybe I’ll just stick in 5 hard-coded links and call it a day. :)

Thanks!

Sincerely,
Mr. Previously Competent, now known as Mr. Idiot

Offline

#10 2009-02-01 03:06:06

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

Re: active_class not active on first item in section_list?

Oh dear, I hope it wasn’t entirely me who made you feel this way…

OK, for a bunch of static pages, that don’t need a different layout, the simplest solution in my view is this: don’t use sections, write all your articles in one section. So all your ‘pages’ are in Txp ‘articles’. Set ‘on front page’ to ‘no’ for this section. In Admin > Preferences, set permanent link mode to /title. You only need one page template, that contains:

1. the menu, created not with section_list but with article_custom:

<txp:article_custom>
	<txp:if_first_article><ul></txp:if_first_article>
	<li><txp:permlink><txp:title /></txp:permlink></li>
	<txp:if_last_article></ul></txp:if_last_article>
</txp:article_custom>

(You can add sort order, active class etc. later.)

2. an article tag to display your content:

<txp:if_section name=""><!-- if we are on the front page -->
	<txp:article_custom id="123"><!-- article id '123' will be displayed on the front page,
		if you don't want it to appear in the menu, make it 'sticky' instead of 'live' -->
		<h2><txp:title /></h2>
		<txp:body />
	</txp:article_custom>
<txp:else />
	<txp:article limit="1">
		<h2><txp:title /></h2>
		<txp:body />
	</txp:article>
</txp:if_section>

This makes a very basic site. And it isn’t that much work, so you can give it a try and if it doesn’t suit you you won’t have spent too much time on it ;)

Here is an article that will probably help you understand how Txp works. And as I said, you can ask whatever you want over here.

Last edited by els (2009-02-01 03:08:35)

Offline

#11 2009-02-01 04:59:02

flamenco
Member
Registered: 2009-01-07
Posts: 18

Re: active_class not active on first item in section_list?

Wow, Els,
That’s an object lesson… simply awesome. Thank you very much. There’s no way I could have ever guessed that. I owe you one.

I humbly know how people must feel when they’re learning in their 2nd or 3rd language. I get that feeling also when I can’t find a Spanish word. :) I did look at that nice instruction page before. It’s very well organized, and will work for a regular linear person, I think, like someone who does well in a university lecture. I got the general concepts fine, even the odd naming conventions actually, but wanted to immediately get practical, and I could not find the code for the details. Impatient. :)

My brain works backwards… I don’t do well with concept descriptions, eventually leading to code much later. I like to see and touch code, start changing things, and see what happens, and maybe pick up terminology and concepts along the way. And with the default template, doing that gives you basura, as they say. ;) (My aggressive approach has worked for me more often than not. Here, I surrender!)

Or better yet, have a plan, and figure out what code works with my plan. That’s why I just started building after the tuts didn’t get me excited. And I intuitively felt that my code must be goofy, and indeed it is. What’s sillier than making a separate section for each single article?

But your code and description is clear as glass (I think!), and I’ll give it a try soon.

Very nice job, and we’ll talk again. Who knows, maybe after a couple months, I can answer a question! You’re an ace!
Dank, Thanks.
D

Offline

#12 2009-02-01 17:35:30

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

Re: active_class not active on first item in section_list?

flamenco wrote:

I like to see and touch code, start changing things, and see what happens, and maybe pick up terminology and concepts along the way.

Yep, that’s about the way I usually do things (and it’s exactly why I still haven’t managed to learn PHP properly ;))

What’s sillier than making a separate section for each single article?

It’s not silly. There can be good reasons for creating separate sections, I’ve used both ways for different sites. It all depends on the site’s demands. If you expect to need ‘subpages’ sooner or later, sections would be a better choice.

There are several tutorials, varying from Destry’s essays to start-from-scratch ones, like this one. One of those, or none, might suit a particular user. Another way to get a grasp of it, is to find a template that matches your needs more or less, download it and figure out what tags are used to make it work the way it does.

Txp has this built-in feature/bug/whatever, don’t go looking for it, you’ll know it when you come across it: the click :) As Peter said:

Textpattern users often say they came to a point where something clicked and after that Textpattern became clear and simple.

Offline

Board footer

Powered by FluxBB