2

Reading the expression engine forum display forum topics There is no count variable. I want to alternate classes for each result so it can have different background colors. There is no other property I can use that would also stand in for it for alternation. Anyone know what I can do for alternating classes for each forum topic result?

I don't know if anyone will see this, I miss the forums.

  • Have you tried the switch tag? It may work even though it is not in the documentation – Johnathan Waters Mar 3 '14 at 18:58
1

Use the {switch} tag. Separate switches by the | pipe character, they will cycle through.

{exp:channel:entries channel="news" limit="10" switch="green|blue|red"}
    <h2 class="{switch}">{title}</h2>
{/exp:channel:entries}

Will output

<h2 class="green">My title</h2>
<h2 class="blue">My title</h2>
<h2 class="red">My title</h2>
<h2 class="green">My title</h2>
<h2 class="blue">My title</h2>
<h2 class="red">My title</h2>
etc...
| improve this answer | |
  • I believe the switch only works for entries loops not the exp:forum loops. – Reverie123 Apr 1 '14 at 3:22
0

You also can do this is pure CSS using the CSS3 nth-child pseudo selector.

#yourtableid tr:nth-child(odd) {
  background-color: #99ff99;
}
| improve this answer | |
  • Perfect, this should work without having to enabling php for the template (was my original solution)! – Reverie123 Apr 1 '14 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.