Okay, here’s what you can do for comments…
Open your favourite text editor and paste the following code in it:
<?php
function my_comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb;
global $comment_count_cache;
if (! is_single() && ! is_page()) {
if ( !isset($comment_count_cache[$id]) )
$comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';");
$number = $comment_count_cache[$id];
if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) {
echo $none;
return;
} else {
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
echo(__('Enter your password to view comments'));
return;
}
}
echo '<a href="';
if ($wpcommentsjavascript) {
if ( empty($wpcommentspopupfile) )
$home = get_settings('home');
else
$home = get_settings('siteurl');
echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id;
echo '" onclick="wpopen(this.href); return false"';
} else { // if comments_popup_script() is not in the template, display simple comment link
if ( 0 == $number )
echo get_permalink() . '#respond';
else
comments_link();
echo '"';
}
if (!empty($CSSclass)) {
echo ' class="'.$CSSclass.'"';
}
echo ' title="' . sprintf( __('Comment on %s'), strip_tags($post->post_title) ) .'">';
comments_number($zero, $one, $more, $number);
echo '</a>';
}
}
}
?>
Make sure that there are no empty spaces before <?php
and after ?>
. Now save the file as my-hacks.php
and upload it to your root wordpress directory.
Next, in the administration panel, go to Options > Miscellaneous and check “Use legacy my-hacks.php file support”.
Now, search for comments_popup_link
in your theme’s files. Replace every occurrence with my_comments_popup_link
. You don’t have to change the function’s parameters.
That should work.
(Also, about post titles, you also need to change the code for your post titles in single.php
, just like you did for index.php
.)