scriptygoddess

04 Jun, 2004

Comment Hilighting

Posted by: Jennifer In: WordPress scripts

One of the things I wanted to do was be able to highlight certain posts that were particularly important. Probably not useful on all types of blogs – but on this one, where some comments with links, or suggestions, or alternate methods of doing something, may go unnoticed in a busy, highly commented post, I wanted to be able to point to a few and make sure people saw them…

I had actually originally asked MooKitty for a plugin/hack that would do it:
Here is her script.

I think her solution is very well-done. It means updates to the interface so you can easily see which post was noted as "important", etc. However, after having lived through a few MT upgrades, I've been trying to avoid editing any core WordPress code, so that I don't have to start worrying about a dozen hacks I could lose when I upgrade my CMS.

Here's my solution. It may not be as elegant, but it gets the job done. :)

On your wp-comments.php file, after this line of code:

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

Add the following:

<?php
$isImportant = false;
if (stristr($comment->comment_content, "<!–important–>")) {
$isImportant = true;
} ?>

Then before your comment text begins (with <?php comment_text() ?>) add this:

<?php if($isImportant) { echo '<div class="importantcomment">';} ?>

To close the DIV tag – BEFORE the ending LI tag for the comment add this

<?php if($isImportant) { echo '</div>';} ?>

Then add a style "importantcomment" to your style sheet. Style however you like.

When you want to mark a comment as "important" simply edit it and in the very beginning of the comment add this:

<!–important–>

The kind of neat thing is, I can see an easy hack/addition to this where you could have "levels" of importance – with each level having a different style.

The drawbacks of my idea vs. MooKitty's is that with mine, techincally anyone can add the "important" text to their comment, and make theirs stand out. (You would just need to edit it to remove the important notation – if you wanted to). As well, without looking at your blog, or clicking edit on each comment, there's no easy way to tell from the comment listing pages which comments have been marked as important – like you can with hers.

So, pick your poison, I guess. But wanted to show you both options.

1 Response to "Comment Hilighting"

1 | Marya

May 26th, 2005 at 9:05 pm

Avatar

I really would like to use the script, but I'm having a little trouble… I already have a style set for my comments (like font and background color), and I wish to maintain it and add a different one for my own comments… Even though I understand nothing of php coding, I tried to adapt your code for something like this:
<?php if($isByAuthor ) { echo "<div class="authorcomment"> ;} else { echo "<div class="commenttext">" ;} ?>
and this:
<?php if($isByAuthor ) { echo "</div>" ;} else { echo "</div>" ;} ?>
but it obviously did not function… Is there any way to make such code work? Thanks! :)

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements