XF 1.2 Alternating Color Rows Without Any Plugin or File Uploads

shabbirbhimani

Active member
Had an alternating row color for vBulletin without a plugin and wanted something similar for Xenforo. I know this is not the best way to be doing it and as Xenforo is on MVC structure may not be recommended as well but the simplicity of it made me to share it here.

In thread_view template, Find

HTML:
    <xen:foreach loop="$posts" value="$post">

And replace with
HTML:
    <xen:set var="$i">0</xen:set>  
    <xen:foreach loop="$posts" value="$post">
      <xen:set var="$j">{$i}</xen:set>
      <xen:set var="$i">{xen:calc '{$j}+1'}</xen:set>
      <xen:if is="{$i}%2==0">
        <xen:set var="$AltColor">Even</xen:set>
      <xen:else/>
        <xen:set var="$AltColor">Odd</xen:set>
      </xen:if>

In message template find

HTML:
<li id="{$messageId}" class="message

And add the class as follows

HTML:
<li id="{$messageId}" class="{$AltColor} message

Finally Add the following to message.css template

HTML:
.messageList .Even, .messageList .Even .primaryContent {background:@primaryLightest;}

Enjoy !!!
 
The CSS Paul has in the FAQ linked above works on posts regardless of their ID. It works on the position of the <li> element in the HTML, which is either even or odd independent of post IDs.
 
Back
Top Bottom