Well, writing this topic I feel like there is nothing to say, so I guess it will be written very briefly ... I'm just a lazy fat guy.
The output of the comment list, the official one is the following
The code is as follows |
Copy Code |
<?php $comments->listcomments ();?> |
The official output in the definition of CSS is a bit awkward, so many themes are used in the grasshopper "Custom Comment List Style" in the method (Grasshopper is the great God AH ~ ~)
The next part is based on the grasshopper code.
Well, nonsense so much, first on the effect, is the following figure this way, the first time back indent, the second layer is no longer indented, to maintain alignment
Here's how it's implemented.
First look at the grasshopper original piece of code:
The code is as follows |
Copy Code |
<?php function threadedcomments ($comments, $options) { $commentClass = '; if ($comments->authorid) { if ($comments->authorid = = $comments->ownerid) { $commentClass. = ' Comment-by-author '; } else { $commentClass. = ' Comment-by-user '; } } $commentLevelClass = $comments->_levels > 0? ' Comment-child ': ' Comment-parent '; ?> <?php}?>
<li id= "li-<?php $comments->theid ()?>" class= "comment-body<?php if ($comments->_levels > 0) { Echo ' Comment-child '; $comments->levelsalt (' comment-level-odd ', ' Comment-level-even '); } else { Echo ' comment-parent '; } $comments->alt (' comment-odd ', ' Comment-even '); Echo $commentClass; ?> "> |
This section is a judgment Comment ID, a parent comment or a child comment, and an odd even number to determine the comment ID, which in fact is added to the sub-comments section with a depth of judgment.
The modified code is as follows:
The code is as follows |
Copy Code |
<?php function threadedcomments ($comments, $options) { $commentClass = '; if ($comments->authorid) { if ($comments->authorid = = $comments->ownerid) { $commentClass. = ' Comment-by-author '; } else { $commentClass. = ' Comment-by-user '; } } $commentLevelClass = $comments->_levels > 0? ' Comment-child ': ' Comment-parent '; $depth = $comments->levels +1; Add a sentence ?> <?php}?>
<li id= "li-<?php $comments->theid ()?>" class= "comment-body<?php if ($depth > 1 && $depth < 3) {//The judgment here should be modified Echo ' Comment-child '; $comments->levelsalt (' comment-level-odd ', ' Comment-level-even '); } ElseIf ($depth > 2) { Echo ' Comment-child2 '; $comments->levelsalt (' comment-level-odd ', ' Comment-level-even '); } else { Echo ' comment-parent '; } $comments->alt (' comment-odd ', ' Comment-even '); Echo $commentClass; ?> "> |
In fact, is a word of the matter, is added a judgment, the child comments whether the depth of more than 2, and then give a different ID to define the style, I also pretended to do a good job of the article out, well, I am a parallel imports ...