What's new? | Help | Directory | Sign in
Google
comment-highlighter
Wordpress Plugin: Comment Highlighter
  
  
  
  
    
Search
for
Updated Jan 24, 2008 by janpolsen
Labels: Featured
FAQ  
Frequently Asked Questions

Could you please explain exactly where the PHP line should be added?

Most themes (if not all of them) uses shows each comment as a <li>...</li>-tag, so the whole purpose is to add a class to this tag.

Looking at the default Wrodpress theme, then the essential lines in comment.php looks like this:

/* This variable is for alternating comment background */
$oddcomment = 'class="alt" ';

<ol class="commentlist">

<?php foreach ($comments as $comment) : ?>

  <li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
    <cite><?php comment_author_link() ?></cite> Says:
    <?php if ($comment->comment_approved == '0') : ?>
    <em>Your comment is awaiting moderation.</em>
    <?php endif; ?>
    <br />

    <small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('edit','&nbsp;&nbsp;',''); ?></small>

    <?php comment_text() ?>

  </li>

<?php
  /* Changes every other comment to a different class */
  $oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';
?>

<?php endforeach; /* end for each comment */ ?>

</ol>

In line 1 a variable called $oddcomment is set to class="alt" and that value is changed after displaying each comment. The result of this is, that every other comment will have a class name called alt, which again can have it's own style. Anyways, those lines of codes are not necessary when using this plugin, since the plugin will handle those classes itself.

The above default theme for comments can be rewritten to utilize the Comment Highlighter plugin as follows:

<ol class="commentlist">

<?php foreach ($comments as $comment) : ?>

  <li class="<?php if(function_exists('CommentHighlight')) CommentHighlight(); ?>" id="comment-<?php comment_ID() ?>">
    <cite><?php comment_author_link() ?></cite> Says:
    <?php if ($comment->comment_approved == '0') : ?>
    <em>Your comment is awaiting moderation.</em>
    <?php endif; ?>
    <br />

    <small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('edit','&nbsp;&nbsp;',''); ?></small>

    <?php comment_text() ?>

  </li>

<?php endforeach; /* end for each comment */ ?>

</ol>

So to get back to your question, then you can see the PHP line code has been placed inside the comment loop (which starts at line 3 above). To be more exact, then it is placed as an attribute to the <li>...</li>-tag (in line 5 above).

You need to look at your comments.php and find a structure like...

... foreach $comments ...
...   <li id="xxx"> ...
...   </li> ...
... endforeach ...

and replace the <li>-tag to look like...

...   <li class="<?php if(function_exists('CommentHighlight')) CommentHighlight(); ?>" id="xxx">

instead.

I hope that helps finding the right place to add the line of code. If not then feel free to post or send me the comments.php file, then I can pinpoint the exact spot .


Comment by jaledwith, Feb 08, 2008

I'm trying to use your plugin while using the K2 theme. The K2 comment php file already attributes a class in the <li> tag. It looks like this.

<li id="comment-<?php comment_ID(); ?>" class="<?php k2_comment_class($comment_index); ?>">

So how would I use your plugin in this scenario?

Comment by janpolsen, Feb 08, 2008

You should be able to just add the function inside the class attribute like:

<li id="comment-<?php comment_ID(); ?>" class="<?php k2_comment_class($comment_index); ?> <?php if(function_exists('CommentHighlight')) CommentHighlight(); ?>">

Make sure to remember the space between the two <?php ... ?> code blocks.

Comment by d...@dcfountain.com, Mar 06, 2008

I'm interested in using comment-highlighter only to change the background or possibly text color for comments I make as the post author (in reply). I'm relatively new at CSS and XHTML coding, and am unsure exactly what I must do to activate the new criteria I've set in the plug-in's options panel. My 2 questions:

1) Do I need to specify/write code for the "class", or does the plugin automatically generate that?

2) What code do I insert into the comment.php file to activate this type of highlight, how do I specify the color I want to use for the highlight, and where should I insert the code -- same as above?

Thanks -- I'm looking forward to putting to work what appears to be a very useful plugin!

Comment by janpolsen, Mar 07, 2008

# The rules you can set up with this plugin will "only" generate a class name, which you have to place within your comment code. You still have to manually create the corrosponding CSS class in your style sheet file.

# If you look at the difference in the code between the above two comments to this page (from jaledwith and myself), then you can see exactly what code you have to insert into comment.php

Comment by rinamf, Mar 26, 2008

Well, I'm trying to make the plug-in work, but all it says on the Options-page is "This plugin only works with curl activated in PHP". http://no.php.net/curl Any ideas what to do?

Comment by janpolsen, Mar 28, 2008

curl is a module that can be compiled with PHP. Without that module enabled at your host, then this plugin simply wont work :(.

Comment by ladycrow, Jul 06, 2008

Does this work with 2.5?

Comment by janpolsen, Jul 06, 2008

Yes it does :)


Sign in to add a comment