Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-12-17 06:38:28

mattmikulla
Member
From: Nashville Tennessee
Registered: 2004-08-25
Posts: 281
Website

Assign even or odd class to table rows output by article lists

Howdy. I am working on a catalog and outputting the article list into an html table. Is there a way or plugin that would allow me to assign an even and odd classes to alternating table rows so I can style the table rows differently?

I’ve used the txp:ajw_comment_alt plugin for comments before and I’m wondering if someone has a similar solution for tables.


Art Rogue – Fine Art Photography

Offline

#2 2007-12-17 06:48:42

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Assign even or odd class to table rows output by article lists

Offline

#3 2007-12-17 08:36:44

mattmikulla
Member
From: Nashville Tennessee
Registered: 2004-08-25
Posts: 281
Website

Re: Assign even or odd class to table rows output by article lists

Not sure how I would use it.

My article form is

<tr>
<td><a href="<txp:permlink />" title="<txp:title />"><txp:article_image thumbnail="1" /></a></td>
<td><a href="<txp:permlink />" title="<txp:title />"><txp:title /></a></td>
<td><txp:custom_field name="width" /></td>
<td><txp:custom_field name="height" /></td>
<td><txp:custom_field name="rabbet" /></td>
<td>$<txp:custom_field name="length_price" /></td>
<td>$<txp:custom_field name="chop_price" /></td>
</tr>

Art Rogue – Fine Art Photography

Offline

#4 2007-12-17 08:42:17

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Assign even or odd class to table rows output by article lists

Something like this might work (not tested):

<tr<txp:zem_nth step="1" of="2"> class="odd"</txp:zem_nth>>
<td><a href="<txp:permlink />" title="<txp:title />"><txp:article_image thumbnail="1" /></a></td>
<td><a href="<txp:permlink />" title="<txp:title />"><txp:title /></a></td>
<td><txp:custom_field name="width" /></td>
<td><txp:custom_field name="height" /></td>
<td><txp:custom_field name="rabbet" /></td>
<td>$<txp:custom_field name="length_price" /></td>
<td>$<txp:custom_field name="chop_price" /></td>
</tr>

It would assign a class="odd" attribute to table rows #1, 3, 5, …, while assigning no class at all to even rows. Do not get scared by the irregular brackets around the tr element. Modify ad lib.

Offline

#5 2007-12-17 14:49:27

mattmikulla
Member
From: Nashville Tennessee
Registered: 2004-08-25
Posts: 281
Website

Re: Assign even or odd class to table rows output by article lists

Blammo! Worked like a charm. Thanks for the help. I looked at the irregularity of the plugin early in the morning before sleep and was put off.


Art Rogue – Fine Art Photography

Offline

#6 2007-12-18 16:58:09

mattmikulla
Member
From: Nashville Tennessee
Registered: 2004-08-25
Posts: 281
Website

Re: Assign even or odd class to table rows output by article lists

I wonder if javascript might be a lighter option.

I found this tutorial and it only ends up being 5 lines of code.

I haven’t looked at the nth plugin code, but I’m sure it’s more complex and probably requires more server and processor hits. I don’t necessarily need the zebra striping, so if someone has javascript turned off no biggie.

Just wondering what would be a better decision. Plugin or Javascript? You all can weigh in with opinions.

Last edited by mattmikulla (2007-12-18 16:59:28)


Art Rogue – Fine Art Photography

Offline

#7 2007-12-18 17:02:17

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Assign even or odd class to table rows output by article lists

I wonder if javascript might be a lighter option.

Not necessarily as many people do not have javascript enabled.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#8 2007-12-18 19:09:59

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: Assign even or odd class to table rows output by article lists

mattmikulla wrote:

I wonder if javascript might be a lighter option.
Just wondering what would be a better decision. Plugin or Javascript? You all can weigh in with opinions.

If I’m right, from 1 to 5 percents of users have Javascript swithed off. I think we can disregard this amount of users and use JS, especially if we have included jQuery jet :) WHy jQuery? Because we need 3 lines of code to make required highlight.

But at the same time, we can use server-side highlighing if it will be a huge table – JS can make page too heavy.


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#9 2007-12-19 07:50:07

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Assign even or odd class to table rows output by article lists

the_ghost wrote:

If I’m right, from 1 to 5 percents of users have Javascript swithed off.

But many more ff users have the noscript plugin installed


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#10 2007-12-19 08:46:56

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Assign even or odd class to table rows output by article lists

But many more ff users have the noscript plugin installed

As I do. I just hate javascript ads and trackers. And I’m not the only one.

Cheers!

Last edited by Gocom (2007-12-19 08:47:56)

Offline

Board footer

Powered by FluxBB