Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

[Help] Alternating Row Color in Custom Theme

edited January 2007 in Vanilla 1.0 Help
I'm working on a custom theme+style right now, and I've run into a brick wall with alternating background colors on the Discussion list.

It would be neat if I could somehow add a another class to the #Discussion_# tag, that alternates between rownumber_0 or rownumber_1. I've tried doing this in the theme page, but it won't let me do anything other than echo the number.

Any ideas or help? I know next to nothing of the Vanilla theme backend. I guess I could always take the easy route out and style #Discussion_2 different than #Discussion_3 and so on.


  • edited August 2006
    Customize discussion.php:

    In the beginning of the file, right after:
    $LastUrl = GetLastCommentQuerystring($Discussion, $this->Context->Configuration, $CurrentUserJumpToLastCommentPref);
    if (!isset($row_count)) { static $row_count = 1; }

    Next, right after:
    <li id="Discussion_'.$Discussion->DiscussionID.'" class="Discussion'.
    add (you can customize Odd/Even to be whatever classnames you want):
    ($row_count & 1 ? ' Odd' : ' Even').

    Finally, at the end of the file, after:

    (Edit: updated to correct code.)
  • Thanks, I see how that is supposed to work, but it ends up just outputting the class "Odd" each time.
  • Are you sure you've got the "static" bit in front of $row_count = 1?
  • Yup, double-checked.
  • Have you got your theme activated?
  • Absolutely. That is an abandoned theme that I was working on, ignore the terrible mess. I'm just using it to test this whole thing.
  • Is this working on your server, is it known to work? It looks as though all the code is working as it should, but it is not looping through the "function" for each discussion.
  • That's really weird. I tested it out myself and I swear it was working. Looked again, and it wasn't. 8x

    Try this, it should act correctly now:

    Instead of:
    static $row_count = 1;

    if (!isset($row_count)) { static $row_count = 1; }
  • Beautiful, that worked. Thank you so much!
  • edited August 2006
    so based on above code the css would be like this ? #discussions .odd or .even ?

    I think I misunderstood this discussion is this for alternating coments or only for discussions ;-)
  • It's for alternating row colors on the discussion list, but it could be easily adapted for alternating colors on the comments page.

    I used it on my in-progress style, if you want to see it in action.
  • ah I see, nice

    how would we adapt this to alternating comments ?
  • Just add the same code to your comments.php page.
  • the code in comments.php appears to be very different then that of discussion.php
  • You can now use "Alternate" in Vanilla 1.0.1 to use alternating background colors.
  • Alternate ? what is that
  • If you check this page's HTML source, you can see it:
    <li id="Comment_38367"> ... <li id="Comment_38368" class="Alternate"> ... <li id="Comment_38369"> ... <li id="Comment_38370" class="Alternate"> ...
    If you check my green-theme you can see how I use it on the comment section
  • Ah, nice. I still haven't found the time to update to 1.0.1 so I didn't see it yet.
  • interesting, i'm using 1.0.1 and the class="Alternate" in source code do not exist how come ?
  • In the discussion page it won't be <samp>class="Alternate"</samp>, Alternate will be at the end of a list of classes (class="bla bla bla Alternate"). On the comments page it should be; if it isn't then you probably forgot to update a theme file or something.
This discussion has been closed.