How to Add Numbers Into Comments

Hello! I know i’m late. But im working hard. I had a tow weeks of a travel for works. I was away from computer. Than i’m here now :) This trick is a comments.php hack :) Let’s begin…

Here is the code;

We will edit your WordPress’ theme. You should make a backup of comments.php. If you make a backup, continue…

We will edit comments.php and we add some code into this file. First, look at the code;

<ol id="commentlist">

<?php $i = 1; ?>
<?php foreach ($comments as $comment) : ?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment, 32 ); ?>
<?php comment_text() ?>

<p><cite><?php comment_type(_c('Comment|noun'), __('Trackback'), __('Pingback')); ?> <?php _e('by'); ?> <?php comment_author_link() ?> &#8212; <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite> <?php edit_comment_link(__("Edit This"), ' |'); ?></p>
<div class="commentnumber">#<?php echo $i; ?></div>
</li>
<?php $i++; ?>

<?php endforeach; ?>

Do you see the added code? If you don’t i will write them here. Add this codes into your comments.php like me;

<?php $i = 1; ?>
<div class="commentnumber">#<?php echo $i; ?></div>
<?php $i++; ?>

If you want to add link to reply. Just change  #<?php echo $i; ?> with this code;

<a href="#comment-<?php comment_ID() ?>" title="">#<?php echo $i; ?></a>

Finally, The CSS. Add this css into your style.css;

/* Comment Numbers */
.commentnumber {
position: absolute;
right: 5px;
top: 5px;
font-size: 18px;
color: #454545;
}
.commentlist li {
position: relative;
}
/* Comment Numbers */

That’s All. This is the screenshot :)


Related posts:

If you enjoyed this post, make sure you subscribe to my RSS Feed

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
 

Highslide for Wordpress Plugin