Add a floor number to the message in WordPress

Source: Internet
Author: User
This article mainly introduces to the WordPress in the message plus the floor number of the PHP code example, here only for the main comment and not for the cascading building in the comments. We hope to help you.

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 = ' <p class= ' floor ' > '; if (get_option (' comment_order ') = = = ' desc ') {//reverse $commentcountText. =--$commentcount.  ' Building '; } 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.   ' Building ';  Break }} $commentcountText. = ' </p ' > '; } }


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 =' <p class= ' floor ' > '; if (get_option (' comment_order ') = = = ' desc ') {//reverse $commentcountText. =--$commentcount.  ' Building '; } 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.   ' Building ';  Break }} $commentcountText. = ' </p ' > '; }} extract ($args, extr_skip); if (' p ' = = $args [' style ']) {$tag = ' P '; $add _below = ' comment ';} else {$tag = ' li '; $add _below = ' p-comment ';}? > <<?php echo $tag?> <?php comment_class (Empty ($args [' Has_children '])? ': ' parent ')?> id= "comment-<?php comment_id ()?>" > <?php if (' p '! = $args [' style ']):?> <p id= " p-comment-<?php comment_id ()?> "class=" Comment-body "> <?php endif;?> <p Class= "Comment-author vcard" > <?php if ($args [' avatar_size ']! = 0) echo get_avatar ($comment, $args [' avatar_size ']);? & Gt <?php printf (__ (' <cite class= "FN" >%s</cite> <span class= "says" >says:</span> "), get_ Comment_author_link ())?> </p><?php if ($comment->comment_approved = = ' 0 '):?> <em class= " Comment-awaiting-moderation "><?php _e (' Your comment is awaiting moderation. ')?></em> <br/><? PHP endif;?> <p class= "Comment-meta commentmetadata" ><a href= "<?php Echo htmlspecialchars (get_comment_ Link ($comment->comment_id))?> "> <?php/* translators:1: Date, 2:time */printf ('%1 $ s at%2$s '), GE T_comment_date (), Get_comment_time ())? ></a><?php Edit_comment_link (' (edit) '), ', ');?> </p > <?php comment_text ()?> <p class= "Reply" > <?php comment_reply_link (Array_merge ($args, Array (' add_ Below ' + $add _below, ' depth ' = $depth, ' max_depth ' => $args [' max_depth ']))?> </p> <?php echo $commentcountText; Main comment Floor number-by zwwooooo?> <?php if (' p '! = $args [' style ']):?> </p> <?php endif;? ><?php}


Related recommendations:

PHP turns into a directory tree based on an array of paths

How to make general settings in WordPress

Using WordPress to develop a small program in real-life tutorial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.