Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
Re: Assign even or odd class to table rows output by article lists
Offline
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
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
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
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
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
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
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
Offline