Comment question

Jeroen Coumans - March 5, 2006 - 11:13

Hi all,
I want to display the comments in an ordered list (<ol>). Each comment should be wrapped in a list item which I want to have alternate classes, e.g. <li class="odd"> and <li class="even">. How can I do this with phptemplate in 4.7? Any help is greatly apreciated.

You should be able to

Zen - March 11, 2006 - 08:21

You should be able to override the theme functions (used in the comment module) in your phptemplate theme. I'm pretty sure the docs cover this.

-K

Help me out here..?

Jeroen Coumans - March 12, 2006 - 14:36

I'm sorry, but I need a little more help; my PHP/programming skills are very limited (I'm a designer, not a software engineer). I'm sure the docs cover how to override theme functions, but I have no idea how to do this (and I couldn't find an example to get me started). What I have done right now is hack comment.module to output the proper code, but I'd rather have it in my template.php, obviously.

My hacked comment module: http://jeroencoumans.nl/files/hacked-comment (I use Drupal 4.7 beta 5/CVS)

I actually had a looksee

Zen - March 12, 2006 - 18:10

I actually had a looksee just now and themes (bluemarine for e.g.) come with a comment.tpl.php which looks like it should be enough to do what you want. The zebra striping might require a little code.. Something like (I'm extemporising here..):

<?php
 
if (!isset($GLOBALS['comemnt_tracker']) {
   
$GLOBALS['comment_tracker'] = 0;
  }
  if (
$GLOBALS['comment_tracker']++ % 2 == 0) {
   
$zebra_class = 'even';
  }
  else {
   
$zebra_class = 'odd';
  }
?>

  <div class="comment <?php print $zebra_class; ?>"> ...

I'm not familiar with the theming system either.. There very likely is a better way to do this, but this should do the trick fine..

The GLOBALS is required to retain the last value as each comment is added. The % operator in the code above is the modulo/remainder operator that is being used to check if the tracker is an even or odd number.

You can replace the existing mark-up with whatever you prefer.

Best of luck :)
-K

 
 

Drupal is a registered trademark of Dries Buytaert.