Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Alternating background on comments  (Read 441 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Alternating background on comments
« on: February 16, 2012, 04:14:51 PM »

One of our members was looking for a way of having a different background on every second comment when there are several comments on an article - Here.

For sNews 1.6....
Here is a simple variation on the one sNews Dude Patric Ahlqvist worked on for sNews 1.5. NOTE - this is a basic method of getting alternating background on comments so you will need to play with the styling to get it more the way you want it.

Step 1: In snews.php, find the $tags['comments'] string inside the // INFO LINE TAGS function:
Code: [Select]

$tags['comments'] = '<div class="comment">,<p class="date">,name, '.l('on').' ,date,edit,</p>,<p>,comment,</p>,</div>';

Comment it out (as the default string) and add this new one below it so your function will now be:
Code: [Select]
<?php // DO NOT COPY THIS TAG

// INFO LINE TAGS (readmore, comments, date)
function tags($tag) {
$tags = array();
   $tags['infoline'] = '<p class="date">,readmore,comments,date,edit,</p>';
// default string
//$tags['comments'] = '<div class="comment">,<p class="date">,name, '.l('on').' ,date,edit,</p>,<p>,comment,</p>,</div>';
// Alternating comments background mod
$tags['comments'] = '<div class="comment_div,style">,<div class="top,topbox,">,name, '.l('on').' ,date,edit,</div>,<div class="bottom">,comment,</div>,<br style="clear: both;" /></div>';
return $tags[$tag];
}

// DO NOT COPY THIS TAG ?>


Step 2:  Further down in snews.php, in the // COMMENTS function, find:
Code: [Select]

foreach ($tag as $tag) {
switch (true) {


And... under it, paste in the following:
Code: [Select]
<?php // DO NOT COPY THIS TAG

// Alternating comments background mod - 2 strings
case ($tag == 'style'): echo $commentNum %== ' border_even' ' border_odd'; break;
case ($tag == 'topbox'): echo $commentNum %2== ' top_even' ' top_odd'; break;

// DO NOT COPY THIS TAG ?>


Step 3: Now we need some basic styling in the style.css file so paste the following into it somewhere... and modify it as needed to work with your template styling:
Code: [Select]

/* comments alternating background styling */
.comment_div {
background: #f8f8fa; color: #808080; padding: 0; margin:0 0 5px 0;
border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;font-size: 90%;}
.comment_div p { margin: 0 .5em; padding: 0; }
.top{
position: relative; float: left; margin: 0px 0 0 0px; width: 90%;
padding: 0.5em 1em 0.5em 1em; border-bottom:1px solid #ddd; }
.top_odd{background:#EDECDA}
.top_even{background:#E6E6B3}
.bottom{clear:both;float:left;margin:0em 1em 1em 1em;width:90%;}
.number {clear:both;float:right; margin: 0em 0.8em 0 0; padding: .3em 0;width:20px; }
.num_even  {font-size: 200%;color:#E6E6B3;}
.num_odd {font-size:200%;color:#EDECDA;}
.num_even:hover, .num_odd:hover {color:#ddd;}

« Last Edit: April 16, 2012, 06:22:22 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: Alternating background on comments
« Reply #1 on: February 16, 2012, 08:43:18 PM »

Nice work Key,
Karma+

awesome evening

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: Alternating background on comments
« Reply #2 on: February 16, 2012, 10:09:51 PM »

great variation keyrocks
+ karma from me too. ;)
Logged
“Fifty years of programming language research, and we end up with C++?”