My favorites | Sign in
Project Logo
                
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 :)

Comment by bm.robert.simpson, Jul 28, 2008

Hi there,

I followed your instructions to include class="<?php if(function_exists('CommentHighlight?')) CommentHighlight?(); ?>" but it's giving me an empty class. I've rebuilt the comment highlights in the settings a couple of times and still nothing. I'm using WP2.5.1.

Any ideas?

Cheers, Robert

Comment by janpolsen, Jul 28, 2008

Do you have an URL where I can see it? What are the criterias for the rule you want to trigger?

Comment by bm.robert.simpson, Jul 29, 2008

I'd rather not post the URL publicly but I can email it to you. If you could email me at my username above @gmail.com I'll reply with the URL.

Basically I have a single user who I'm applying a class to, the criteria being used is the email address.

Cheers, Robert

Comment by janpolsen, Aug 05, 2008

I got an email because of a new comment to this page, but for some reason the comment isn't listed here! :(


Comment by jp.horn:

Feature request: Could you also please support User ID in a newer version of the plugin, since email addresses can be easily spoofed. I'd like to bind author id's to specific classes. Thanks for considering this request.


Just to let you know - I think this is a good idea and I will look into implementing this one of these days. Thanks for suggesting it :)

Comment by jp.horn, Aug 06, 2008

Two other requests :) - Add an option to decide whether the conditions should be AND/OR (the current default is OR, and I really need AND) - Let us edit already defined criteria

Thanks for considering and thanks for an excellent plugin!

Comment by jp.horn, Aug 06, 2008

An explanation why I need the AND. I want to bind my email address (or user id when it's done) globally, but still have alternate comments (odd/even). I check Email (and write my email address), Even and Global, but the class is applied to ALL even posts instead of only the posts with my email address. Hope this makes sense :)

Comment by hismuse, Aug 07, 2008

I can't find the <li class in my comment.php.

Comment by janpolsen, Aug 07, 2008

@jp.horn: I am ready with a v0.13 now which contains the user ID and the edit feature, but I would like to give the AND/OR a chance as well, before I release a new version.

However I am not 100% sure I understand what exactly it is you want. Won't you get what you want, if you make three rules - one for your email (or user id), one for the even comments and one for the odd comments?

Converting that to some sample styles: - comments with my email/user id gets a fat border - even comments gets a dark background color - odd comments gets alight background color

Wouldn't that do it?

@hismuse: I need to know at least the theme name and preferably also an URL.

Comment by jp.horn, Aug 08, 2008

@Jan: To be honest I hadn't thought about that, but you're right. Two different classes (even/oneven) AND for User ID would work as well :) Good thinking! I'll check back for the new version and thanks for implementing my greatest wishes.

Comment by janpolsen, Aug 09, 2008

Okies - I will upload the new version then and if it doesn't work as you want, then feel free to get back to me.

Comment by rainchx, Jun 21, 2009

I need to manually flag a comment as "special" in the admin section. Then in comment.php I check the special flag and change the comment according to the rules of that flag. Does your plugin allow this?

Comment by janpolsen, Jun 22, 2009

You can always manually flag comments as "special", since you can use comment IDs as a pattern to check.

If you have created the adminlink on comments, then you can just click on that and you automatically have the comment ID - can't be easier :).

However I have stopped further development on this plugin, so I can't guarantee that it works on WP2.8+


Sign in to add a comment
Hosted by Google Code