Typecho 實現評論無限嵌套顯示的方法教程
其實這個功能是個食之無味,棄之可惜的玩意,針對有需要的人可能來說在頁面佈局方面可能會規整順眼點,對於像吾等沒有什麼互動的博客來說,可能算是多此一舉的東西吧,這篇是個筆記而已,實現方法也算是比較簡單,就是在評論層面上加上判斷,從而實現回覆的平級顯示,從而實現 無限嵌套,具體方法看下面兩段代碼的對比,一目了然!
實現方法根據自己的模板酌情修改,本人所示乃是Typecho原生評論列表函數,提供的是方法和思路,切勿生搬硬套,代碼添修如下:
Before
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?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; ?>"> |
After
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?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; //添加 ?> <?php } ?> <li id="li-<?php $comments->theId(); ?>" class="comment-body<?php if ( $depth > 1 && $depth < 3 ) { //修改 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; ?>"> |
OVER,時候不早了,折騰的筒子們繼續,不折騰的就洗洗睡吧!
悦听有声,路过看看
简繁转换功能在也没刷新下会失效
好东西 谢谢分享先收藏一下下 ...
主题蛮好看的,好像轻博客一样
不错呀
不错哦 收藏了