Recently suddenly found a blog comment floor a bit of a problem, has been set to "show a new comment at the top of each page", that is, the so-called reverse display comments, but the topic only support the order of the comment floor, so the floor and floor number is not on. It's a search. The implementation code found in Zww.me, but does not work after the blog, such as the Limit page display as 25, the article only one comment on the 25 floor. Toss a bit done, make a record, also for everyone reference.
Find the $globals[' comment ' = $comment in the theme file functions.php, followed by the following code:
/* Main Comment counter */global $commentcount, $wpdb, $post; if (! $commentcount) {//Initialize 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 ' and !comment_parent "); $cnt = count ($comments);//Gets the total number of main comments $page = Get_query_var (' cpage ');//Gets the current Comment List page number $cpp =get_option (' Comments_per_page ') ;//Get per page comments Show 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 is the total number of comments} else {$commentcount = $cpp * $page + 1; }}else{//Order $page = Get_query_var (' cpage ')-1; $cpp =get_option (' comments_per_page ');//Gets the number of comments per page $commentcount = $cpp * $page; }}/* Main Comment counter end */if (! $parent _id = $comment->comment_parent) {$commentcountText = '; if (get_option (' comment_order ') = = = ' desc ') {//reverse $commentcountText. =--$commentcount. ' Building '; } else {switch ($commentcount) {case 0: $commentcountText. = ' The couch! '; + + $commentcount; Break Case 1: $commentcountText. = 'The bench! '; + + $commentcount; Break Case 2: $commentcountText. = 'The floor! '; + + $commentcount; Break Default: $commentcountText. = + + $commentcount. ' Building '; Break }} $commentcountText. = ''; } }
Then add the following code to the appropriate location. Output Floor Number
<?php Echo $commentcountText; Main comment Floor number-by Zwwooooo?>
The modified code should look like this (take the official latest wp_list_comments () callback function code as an example):
<?phpfunction 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) {//Initialize 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 ' and !comment_parent "); $cnt = count ($comments);//Gets the total number of main comments $page = Get_query_var (' cpage ');//Gets the current Comment List page number $cpp =get_option (' Comments_per_page ') ;//Get per page comments Show 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 is the total number of comments} else {$commentcount = $cpp * $page + 1; }}else{//Order $page = Get_query_var (' cpage ')-1; $cpp =get_option (' comments_per_page ');//Gets the number of comments per page $commentcount = $cpp * $page; }}/* Main comment counter end */if (! $parent _id = $comment->comment_parent) {$commentcountText =''; if (get_option (' comment_order ') = = = ' desc ') {//reverse $commentcountText. =--$commentcount. ' Building '; } else {switch ($commentcount) {case 0: $commentcountText. = 'The couch! '; + + $commentcount; Break Case 1: $commentcountText. = 'The bench! '; + + $commentcount; Break Case 2: $commentcountText. = 'The floor! '; + + $commentcount; Break Default: $commentcountText. = + + $commentcount. ' Building '; Break }} $commentcountText. = ''; }} 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 ']):?> "class= "Comment-body" > <?php endif;?> <?php if ($args [' avatar_size ']! = 0) echo get_avatar ($comment, $args [' Avatar _size ']);?> <?php printf ('%s says:'), Get_comment_author_link ())?> <?php if ($comment->comment_approved = = ' 0 '):?><?php _e (' Your comment is awaiting moderation. ')?>
<?php endif?> comment_id)?> "> <?php/* translators:1: Date, 2:time */printf ('%1 $ s at%2$s '), Get_comment_date (), Get_comment_time ())? ><?php Edit_comment_link (' (edit) '), ', ');?> <?php Comment_ Text ()?> <?php comment_reply_link (Array_merge ($args, Array (' add_below ' = $add _below, ' depth ' = $depth, ' m Ax_depth ' = + $args [' max_depth ']))?> <?php echo $commentcountText; Main comment Floor number-by zwwooooo?> <?php if (' div '! = $args [' style ']):?> <?php endif;? ><?php}
Style just add it yourself ~ ~