Comments Pagination – Wordpress – Bug Fixed!

Actually, I did not create a plugin but I wrote a code snippet that did this job for me.

Add these lines to comments.php in your active theme folder.

$comments_per_page = 5;
global $post;
$total = $post->comment_count;
if($total > 0) {
$apage=isset($_GET['apage']) ? intval($_GET['apage']) : 1;
$comments=array_slice($comments, intval(($apage-1)*$comments_per_page),intval($comments_per_page));
}

Insert this code right after if ($comments) statement

$commentCounter = (($apage-1)*$comments_per_page);
$from_page = $commentCounter+1;
if($apage == 1) {
$to_page = $comments_per_page;
if($total < $to_page) {
$to_page = $total;
}
}
else {
$to_page = $from_page + $comments_per_page - 1;
if($to_page > $total) {
$to_page = $total;
}
}

Insert this line where you want page links to appear in comments.php.

<?php echo paginate_links( array(
'base' => add_query_arg( 'apage', '%#%#comments' ),
'format' => '',
'total' => ceil($total / intval($comments_per_page)),
'current' => $apage
));

I think this is it. It should work. Give it a try and share your feedback via comments.

Migrate Tags from UTW Tags to Wordpress 2.3 Terms

I was running wordpress 2.0.5 since 2 years and did not get time to upgrade to Wordpress 2.3.

So I decided last week to upgrade to Wordpress 2.3 and I did. I upgrade the same way how wordpress advice us here.

After installation, I did notice it has migrated my categories tables to wordpress 2.3 Terms tables but nothing migrated from Tags tables. I was surprised! Did I make any mistake? Then it comes into my mind, it is Ultimate Tag Warrior plugin, which has created those tables for me not Wordpress.

Now I had to migrate those tags from Tags table to Terms tables. So I wrote a script that does that job for me. I thought let me make that available to you, if someone would like to extend the script and build a smart plugin! (more…)