Typecho Implementation comment Infinite nested display instance

Source: Internet
Author: User
Tags comments

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 ...

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.