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.

1
  • Have you tried the switch tag? It may work even though it is not in the documentation Mar 3, 2014 at 18:58

2 Answers 2

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...
1
  • I believe the switch only works for entries loops not the exp:forum loops.
    – Reverie123
    Apr 1, 2014 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;
}
1
  • Perfect, this should work without having to enabling php for the template (was my original solution)!
    – Reverie123
    Apr 1, 2014 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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