General Community > Scripting Help

Alternating Colors

(1/2) > >>

NIAB:
Hi,

Wondering if anyone knows of a method to change the topic colors so every first or second topic is a different color.

Example:

Topic 1 - Black Background
Topic 2 - White Background
Topic 3 - Black Background
Topic 4 - White Background
Topic 5 - Black Background
Topic 6 - White Background

Colin:
Are you looking for this to be applied to all topics or simply the new topics in the board index?

NIAB:
All topics

NIAB:
Googled SMF Alternating colors, and found a few but none of them seem to help. Any ideas?

NIAB:
Found an easy method of doing it :3


--- Code: ---// Is this topic pending approval, or does it have any posts pending approval?
if ($context['can_approve_posts'] && $topic['unapproved_posts'])
$color_class = !$topic['approved'] ? 'approvetbg' : 'approvebg';
// We start with locked and sticky topics.
elseif ($topic['is_sticky'] && $topic['is_locked'])
$color_class = 'stickybg locked_sticky';
// Sticky topics should get a different color, too.
elseif ($topic['is_sticky'])
$color_class = ($clrCounter++ % 2 == 1 ? 'mytopicbg1' : 'mytopicbg2');
// Locked topics get special treatment as well.
elseif ($topic['is_locked'])
$color_class = 'lockedbg';
// Last, but not least: regular topics.
else
$color_class = ($clrCounter++ % 2 == 1 ? 'mytopicbg1' : 'mytopicbg2');

// Some columns require a different shade of the color class.
$alternate_class = $color_class;
--- End code ---

Works quite well. Posting here for future SMFer's to find.

Navigation

[0] Message Index

[#] Next page

Go to full version