Making my comments different
-
Probably lots of solutions out there for this as I’ve seen it done on lots of sites but I want to make my (admin) comments stand out a little as I often post @replies to peoples comments. I guess I just need to make a class for my own comments… but how?
Suggestions please.
Thanks
-
well, the way I do it works for multi-author blogs too… my theme is based on kubrick so your mileage will vary.
In whichever element contains your comment (in my case it’s a list-item) where you might ordinarily put the class put this:
<?php if($comment->comment_author_email == get_the_author_email()) echo ‘class=”byauthor”‘; else echo $oddcomment; ?>
the $oddcomment functionality is for themes which alternate comment classes based on odd/even numbers, it just inserts the regular class= attribute. I’ve maintained that, but added a completely different class called ‘byauthor’ which is only used if the comment was written by the author of the post.
So I put that in my comments.php file in place of what’s already there?
Here is my current comments.php file, where would I insert that?
<?php if ( !empty($post->post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?> <p><?php _e('Enter your password to view comments.'); ?></p> <?php return; endif; ?> <?php if ( $comments ) : ?> <?php foreach ($comments as $comment) : $commentcounter++; if ($commentcounter % 2 == 0) { ?> <div class="commentodd" id="comment-<?php comment_ID() ?>"><div class="commentcontent"> <p class="comment_header"><span class="comment_name"><?php comment_author_link() ?></span><br /><?php comment_date() ?> - <?php comment_time() ?></p><br /> <?php comment_text() ?> </div></div> <?php } else { ?> <div class="commenteven" id="comment-<?php comment_ID() ?>"><div class="commentcontent"> <p class="comment_header"><span class="comment_name"><?php comment_author_link() ?></span><br /><?php comment_date() ?> - <?php comment_time() ?></p><br /> <?php comment_text() ?> </div></div> <?php } endforeach; endif; ?> <?php if ( comments_open() ) : ?> <div class="post"> <h3><?php _e('Leave a comment'); ?></h3> <?php if ( get_option('comment_registration') && !$user_ID ) : ?> <p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php the_permalink(); ?>">logged in</a> to post a comment.</p> <?php else : ?> <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform"> <?php if ( $user_ID ) : ?> <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="<?php _e('Log out of this account') ?>">Logout »</a></p> <?php else : ?> <p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" /> <label for="author"><small>Name <?php if ($req) _e('(required)'); ?></small></label></p> <p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" /> <label for="email"><small>Mail (will not be published) <?php if ($req) _e('(required)'); ?></small></label></p> <p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" /> <label for="url"><small>Website</small></label></p> <?php endif; ?> <!--<p><small><strong>XHTML:</strong> You can use these tags: <?php echo allowed_tags(); ?></small></p>--> <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p> <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" /> <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /> </p> <?php do_action('comment_form', $post->ID); ?> </form> </div> <?php endif; endif; ?>
well.. yes, but it really depends on what’s already there.
there will be an element there which encases each comment.
<?php foreach ($comments as $comment) : ?> <div class="someclass"> ...
or in my case…
<?php foreach ($comments as $comment) : ?> <li class="someclass"> ...
regardless of the element, you just replace the class=”someclass” part with what I’ve posted.
if your class is actually called “someclass” then the exact code to drop in there would be:
<?php if($comment->comment_author_email == get_the_author_email()) echo ‘class=”byauthor”‘; else echo ‘class=”someclass”‘; ?>
As you know, themes vary wildly, so it’s really kind of hard to tell you exactly where to put it or how it should look — you’ll have to try to understand the code and bend it to suit your theme.
Also, you’ll then need to define the .byauthor class in your theme’s style.css
ok, I was too slow in replying I guess… here’s the deal…
on the line beginning with:
<div class=”commentodd” id=”comment
replace:
class=”commentodd”
with:
<?php if($comment->comment_author_email == get_the_author_email()) echo ‘class=”byauthor”‘; else echo ‘class=”commentodd”‘; ?>
then, as I said above, you’ll need to edit your style.css to create a new class called ‘byauthor’ which you can style to look the way you want it to look.
Yeah, the CSS side I’m fine with. I just kinda suck at PHP and am still learning the intricacies of the loop. Once I get it to call my posts by a different class I’m fine.
Anything you can tell me by looking at my comments.php?
hahaha replies flying past each other
thanks mate, I’ll give that a go.
sweet, that works… now to style it up so it doesn’t look like shit.
glad you got it going ??
It’s lookin good now. Only a couple more tweaks.
https://www.minute44.com/archives/109
Check it out.
- The topic ‘Making my comments different’ is closed to new replies.