NewsFeaturesDownloadsDevelopmentSupportAbout Us

Plugin nestedcomments

From LifeType Wiki

Name: nestedcomments

Download link:

License: GPL

Author: The LifeType Project


This plugin allows to display the comments received for a post in a nested fashion. Different nesting effects can be achieved via CSS.


This plugin requires some changes to the postandcomments.template file. The old Smarty code used to display the post comments should be removed and replaced with new code that allows to show the nested comments.

We should replace this line:

   {foreach from=$comments item=comment}   

with the following contents:

   {assign var=comments value=$nestedcomments->getNestedComments($post)}
   {foreach from=$comments item=comment}

In order to nest the comments, we must check the value of the depth field of the comment in order to know how deeply a certain comment should be nested. We should also keep in mind that the array of comments is already sorted correctly depending on our settings (either newer first or older comments first):

   {assign var=comments value=$nestedcomments->getNestedComments($post)}
   {foreach from=$comments item=comment}
     <div class="comment_{$comment->getValue("depth")}">

In the example above, in order to apply different graphical styles for different levels of nesting we should define up to 6 "comment_X" CSS classes (as in "comment_1", "comment_2", "comment_3", etc) in the CSS file used by your template set.

    .comment_1 {
     margin-left: 10px;
    .comment_2 {
     margin-left: 20px;
    .comment_3 {
     margin-left: 30px;
    .comment_6 {
     margin-left: 60px;


By default there can only be up to 6 levels of nesting but this limit is configurable by editing the plugin file. Change the value of the MAX_NESTED_COMMENTS constant at the top of the pluginnestedcomments.class.php file in case you would like to increase or reduce this value.