Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-05-16 20:48:45

vineonardo
Member
Registered: 2011-08-31
Posts: 128
Website

How to add a special class only to first child of auto generated list?

Hello,
I’m working on a project which requires me add special class to only the first item in an unordered list generated by <txp:upm_article_image /> tag.
I need to generate code like below:

<ul class="something">
<li class="active child">image 1</li>
<li class="child">image 1</li>
<li class="child">image 1</li>
</ul>

I’m not sure if this’s really a textpattern problem, can it be solved by javascript or anything else?

thanks for your time.

Offline

#2 2012-05-16 21:50:39

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: How to add a special class only to first child of auto generated list?

Not sure how upm_article_image works but you might be able to do it using a variable or one of the count plugins such as mdn_count.

jquery way could be

$(".something:first-child").addClass("active");

or

$(".child:first").addClass("active");

Last edited by MattD (2012-05-16 21:54:44)


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#3 2012-05-17 04:53:44

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Re: How to add a special class only to first child of auto generated list?

Instead of adding a class could you achieve your desired result with CSS by using a psuedo class

ul.something>:first-child
OR
li:first-child

Offline

#4 2012-05-17 06:51:36

vineonardo
Member
Registered: 2011-08-31
Posts: 128
Website

Re: How to add a special class only to first child of auto generated list?

Hello and thanks to both of you.

It was a great help for a noob like me :)

It worked the way MattD told, thanks again.

Last edited by vineonardo (2012-05-17 06:56:14)

Offline

#5 2012-05-21 10:25:15

a7atylor
New Member
Registered: 2012-05-21
Posts: 6

Re: How to add a special class only to first child of auto generated list?

You could do this using jquery:

http://api.jquery.com/first/

I often use .last() for removing the border and other styles in lists.

Offline

Board footer

Powered by FluxBB