Recently found that the blog's comment floor is a bit of a problem, the previous set is "at the top of each page to show a new comment", which is called reverse display comments, but the topic only support the order of the comments floor, so the floor and floor number is not right. Search the zww.me found the implementation of the code, but after posting to the blog does not work, such as the Limit page display as 25, the article only one comment when the 25 floor. Toss a bit to finish, make a record, also for everyone's reference.
Find $globals[' comment ' in the subject file functions.php = $comment; Add the following code:
/* Main Comment counter/global $commentcount, $wpdb, $post; if (! $commentcount) {//initialization of floor counter if (get_option (' comment_order ') = = ' desc ') {//Reverse $comments = $wpdb->get_results ("SELECT * from $wpdb->comments WHERE comment_post_id = $post->id and Comment_type = ' and comment_approved = ' 1 ' A
ND!comment_parent "); $cnt = count ($comments);//Get the total number of main comments $page = Get_query_var (' cpage '); Get current Comment List page number $cpp =get_option (' Comments_per_page ') ;//Get per page comment Display quantity if (Ceil ($cnt/$cpp) = = 1 | | ($page > 1 && $page = = Ceil ($cnt/$cpp))
{$commentcount = $cnt + 1;//If the comment is only 1 pages or the last page, the initial value of the main comment total} else {$commentcount = $cpp * $page + 1;
}else{//Order $page = Get_query_var (' cpage ')-1;
$cpp =get_option (' comments_per_page '); Get each page of comments $commentcount = $cpp * $page; }/* Main comment counter end */if (! $parent _id = $comment->comment_parent) {$commentcountText = ' <div class= ' floor ' >
'; if (get_option (' comment_order ') = = ' desc ') {//reverse $commentcountText. =--$commentcount.
' Lou '; else {switch ($commentcount) {case 0: $commentcountText. = ' <span> sofa! </span> ';
+ + $commentcount;
Break Case 1: $commentcountText. = ' <span> bench! </span> ';
+ + $commentcount;
Break Case 2: $commentcountText. = ' <span> floor! </span> ';
+ + $commentcount;
Break Default: $commentcountText. = + + $commentcount.
' Lou ';
Break
}} $commentcountText. = ' </div ' > ';
}
}
Then add the following code to the appropriate location to output the floor number
<?php Echo $commentcountText; Main comment Floor number-by Zwwooooo?>
The modified code should be like this (take the official latest wp_list_comments () callback function code as an example):
<?php function Mytheme_comment ($comment, $args, $depth) {$GLOBALS [' comment '] = $comment;
/* Main comment counter by zwwooooo Modified Gimhoy (http://blog.gimhoy.com)/Global $commentcount, $wpdb, $post; if (! $commentcount) {//initialization of floor counter if (get_option (' comment_order ') = = ' desc ') {//Reverse $comments = $wpdb->get_results ("SELECT * from $wpdb->comments WHERE comment_post_id = $post->id and Comment_type = ' and comment_approved = ' 1 ' A
ND!comment_parent "); $cnt = count ($comments);//Get the total number of main comments $page = Get_query_var (' cpage '); Get current Comment List page number $cpp =get_option (' Comments_per_page ') ;//Get per page comment Display quantity if (Ceil ($cnt/$cpp) = = 1 | | ($page > 1 && $page = = Ceil ($cnt/$cpp))
{$commentcount = $cnt + 1;//If the comment is only 1 pages or the last page, the initial value of the main comment total} else {$commentcount = $cpp * $page + 1;
}else{//Order $page = Get_query_var (' cpage ')-1;
$cpp =get_option (' comments_per_page '); Get each page of comments $commentcount = $cpp * $page; }/* Main comment counter end */if (! $parent _id = $comment->comment_parent) {$commentcountText = ' <div class= ' floor ' > '; if (get_option (' comment_order ') = = ' desc ') {//reverse $commentcountText. =--$commentcount.
' Lou '; else {switch ($commentcount) {case 0: $commentcountText. = ' <span> sofa! </span> ';
+ + $commentcount;
Break Case 1: $commentcountText. = ' <span> bench! </span> ';
+ + $commentcount;
Break Case 2: $commentcountText. = ' <span> floor! </span> ';
+ + $commentcount;
Break Default: $commentcountText. = + + $commentcount.
' Lou ';
Break
}} $commentcountText. = ' </div ' > ';
} extract ($args, extr_skip);
if (' div ' = = $args [' style ']) {$tag = ' div ';
$add _below = ' comment ';
else {$tag = ' li ';
$add _below = ' div-comment '; ?> <<?php echo $tag?> <?php comment_class (Empty ($args [' Has_children '])? ': ' parent ')?> id= "comment-<?php comment_id ()?>" > <?php if (' div '!= $args [' style ']):?> <di V id= "div-comment-<?php C"omment_id ()?> "class=" Comment-body "> <?php endif;?> <div class=" Comment-author vcard "> <?php if ($args [' avatar_size ']!= 0) echo Get_avatar ($comment, $args [' avatar_size ']);?> <?php printf (' <cite class= '
FN ">%s</cite> <span class=" says ">says:</span>"), Get_comment_author_link ())?> </div> <?php if ($comment->comment_approved = = ' 0 '):?> <em class= "comment-awaiting-moderation" ><?php _e (' Your comment is awaiting moderation. ') ?></em> <br/> <?php endif,?> <div class= "Comment-meta commentmetadata" ><a href= "<?ph" P Echo htmlspecialchars (Get_comment_link ($comment->comment_id))?> "> <?php/* translators:1: Date, 2: Time/printf (__ ('%1 $ s at%2$s '), Get_comment_date (), Get_comment_time ())? ></a><?php Edit_comment_link (_
_ (' (Edit) '), ', '; ?> </div> <?php comment_text ()?> <div class= "reply" > <?php comMent_reply_link (Array_merge ($args, Array (' Add_below ' => $add _below, ' depth ' => $depth, ' max_depth ' => $args [' Max_depth '])?> </div> <?php echo $commentcountText; Main comment Floor number-by zwwooooo?> <?php if (' div '!= $args [' style ']):?> </div> <?php endif;?> <?p
HP}
Style just add it yourself ~ ~