• 博客設置
  • 編輯管理
  • 返回首頁
焚花祭秋
Wordpress Typecho 以及周邊知識的一個筆記,成長的過程中相互學習,共同進步!
首頁 歸檔 關於 友鏈 留言
分類
  • 博客.技巧
  • 網絡.主機
  • HOME
  • 博客.技巧
  • Typecho 實現評論無限嵌套顯示的方法教程

Typecho 實現評論無限嵌套顯示的方法教程

作者:焚花祭秋  /   发布时间:July 28, 2015  /   分类:博客.技巧  /   1 Comment

字體大小選擇: [ 超大字體 中型字體 默認字體 ]

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,時候不早了,折騰的筒子們繼續,不折騰的就洗洗睡吧!

上一篇: Typecho 顯示隨機文章或日誌的實現方法 代碼版 下一篇: 網站網頁上面添加字體大小控制的代碼實現方法
    分享到: QQ空間 新浪微博 騰訊微博 開心網 人人網 淘江湖 百度空間
訂閱本站:焚花祭秋
文本標籤:沫, tyoecho評論, 評論嵌套, 無限嵌套
友情聲明:本站所有文章皆為原創,圖文皆為網絡搜索傳播,轉載請以鏈接形式標明原文出處地址,謝謝合作!
本文鏈接:http://tc.muo.me/about-typecho-comments.html [复制]
取消回复
My WeChat

簡繁切換

    • Discuz論壇回覆回貼評論倒敘排列 最新評論靠前
    • WordPress,登陸博客郵件提醒的代碼分享
    • WordPress 重新安裝或者搬家後臺空白或502的解決辦法
    • WordPress,文章頁面添加作者信息,適合多用戶博客
    • LinuxVPS 初級教程P7 LinuxVPS硬盤網絡等性能綜合測試
    • Typecho 顯示隨機文章或日誌的實現方法 代碼版

  • YueTing.Org
    悦听有声,路过看看
  • 自由草
    简繁转换功能在也没刷新下会失效
  • 天地华宇
    好东西 谢谢分享先收藏一下下 ...
  • flippy
    主题蛮好看的,好像轻博客一样
  • flippy
    不错呀
  • qkwu
    不错哦 收藏了
文章 RSS And 评论 RSS
焚花祭秋 Is Powered By Wordpress Theme Desgin By 沫(Muo.me)