The first step: To add the floor number display in the comments, that is to change the WordPress comments internal structure.
The second step: WP in the comments are unified marking. In other words, a comment labeled 256 does not know how many floors it should be in a log. So it's up to us to tell it. For example, suppose the comments in a log are No. 201, No. 207, and No. 311, where No. 311 is the sub-reply of the No. 201 number. So while 311 is the latest comment, the actual display order is 201-311-207 (from top to bottom). How can let 201 know oneself is 1 floor, 311 know oneself is 3 floor? Although the order in which WP 2.7 displays comments is disrupted by the existence of nested rules, in fact it is still in the label order when extracting comments. In other words, the order of the comments in the example is 201-207-311, which is exactly in line with the 1 floor-2 floor-3 floor. So the method is also very obvious, in the extraction of comments when the building number, in the display of comments to extract the number of the building.
1. Grant of the floor number in the extraction of comments:
Found in the comments.php.
The code is as follows |
Copy Code |
<?php if (have_comments ()):?> Or <?php if ($comments): |
followed by the addition
The code is as follows |
Copy Code |
<?php Global $comment _ids; $comment _ids = Array (); foreach ($comments as $comment) { if (get_comment_type () = = "comment") { $comment _ids[get_comment_id ()] = + + $comment _i;} }?> |
2. Drawing of the floor number when the comment is displayed:
Note that this should be done in a custom comment display function (function.php under Themes, open with an editor like Ultraedit32)
The most common is to add the following code after the date is displayed (depending on the situation may be slightly different
The code is as follows |
Copy Code |
<div> ) <span class= "Floor" ><?php global $comment _ids; $comment _floor = $comment _ids[get_comment_id ()]; echo $comment _floor. ' Lou ';?></span> |
If you can not understand the place to leave a message. I'll do my best to help you.
Another way
Combined with the comment loop function of the comments.php template, you can easily solve the floor numbering problem.
Edit the comments.php file and locate the entry code for the following comment loop:
The code is as follows |
Copy Code |
<?php foreach ($comments as $comment):?> |
Add before this code:
The code is as follows |
Copy Code |
<?php $count =1;?>
|
Initialize $count variable, assign 1 where you want the floor number to appear, insert the following code, and of course, how to render the need to customize the style:
The code is as follows |
Copy Code |
<?php echo $count;?>
|
Output floor number after each comment loop function executes, add 1 to the $count variable, so you need to find:
The code is as follows |
Copy Code |
<?php Endforeach;?> |
Join before the end of this loop:
The code is as follows |
Copy Code |
<?php $count + +;?>
|
$count Variable 1 This method is tested in a page-no comment, but it is not supported by page reviews.