Typecho 评论加 @

function.php 文件中添加代码

function getPermalinkFromCoid($coid) {//留言加@  
$db       = Typecho_Db::get();   
$options  = Typecho_Widget::widget('Widget_Options');   
$contents = Typecho_Widget::widget('Widget_Abstract_Contents');   
$row = $db->fetchRow($db->select('cid, type, author, text')->from('table.comments')->where('coid = ? AND status = ?', $coid, 'approved'));   
if (empty($row)) return 'Comment not found!';   
    $cid = $row['cid'];   
    $select = $db->select('coid, parent')->from('table.comments')->where('cid = ? AND status = ?', $cid, 'approved')->order('coid');   
if ($options->commentsShowCommentOnly)   
    $select->where('type = ?', 'comment');   
    $comments = $db->fetchAll($select);   
if ($options->commentsOrder == 'DESC')   
    $comments = array_reverse($comments);   
foreach ($comments as $key => $val)   
    $array[$val['coid']] = $val['parent'];   
    $i = $coid;   
while ($i != 0) {   
    $break = $i;   
    $i = $array[$i];   
}   
$count = 0;   
foreach ($array as $key => $val) {   
    if ($val == 0) $count++;    
    if ($key == $break) break;    
}   
$parentContent = $contents->push($db->fetchRow($contents->select()->where('table.contents.cid = ?', $cid)));   
$permalink = rtrim($parentContent['permalink'], '/');   
$page = ($options->commentsPageBreak)? '/comment-page-' . ceil($count / $options->commentsPageSize) : ( substr($permalink, -5, 5) == '.html' ? '' : '/' );   
return array(   
    "author" => $row['author'],   
    "text" => $row['text'],   
    "href" => "{$permalink}{$page}#{$row['type']}-{$coid}"  
);   
}


/var/Widget/Comments/Archive.php 文件(约第 147 行)中添加代码

<?php  
if($this->parent){   
    $p_comment = getPermalinkFromCoid($this->parent);   
    $p_author = $p_comment['author'];   
    $p_text = mb_strimwidth(strip_tags($p_comment['text']), 0, 100,"...");   
    $p_href = $p_comment['href'];   
    echo "<span>@</span><a href='$p_href' title='$p_text'>$p_author</a>";   
}   
?>

更多效果请查看本站。
参考自 奈何
返回文章列表 打赏
本页链接的二维码
打赏二维码
期待你的评论

15 条评论
  1. 亿七 白银   亿七  

    我看看到底

  2. king 青铜   king  

    @枫叶 测试下

  3. 柒小懿 白银   柒小懿  

    借这里问下,为啥你的网址输入框不用填写http://也可以提交评论呢,可以抽空写个方法吗,谢谢@(太开心)

    1. 小尾巴 王者   小尾巴   博主
      @ 柒小懿

      估计代码里没加限制啥的吧,具体我不造了,用的都是typecho默认的方法

  4. 柒小懿 白银   柒小懿  

    1111正需要这个@(滑稽)

    1. 亿七 白银   亿七  
      @ 柒小懿

      正需要这个

  5. Todo 青铜   Todo  

    说实在的 完全没看懂 添加后既没效果 也没报错@(汗)

  6. 南栀 青铜   南栀  

    不能从主题层面实现 还是比较蛋疼的。 要修改系统文件有点逼死强迫症 @(犀利)

  7. 枫叶 黄金   枫叶  

    你这个复制是真的蛋疼,复制完还转码了。有素质的人会留下文章来源的,你这个整的这个代码没法用了。。。

    1. 小尾巴 王者   小尾巴   博主
      @ 枫叶

      已保留代码格式
      附转码网址:https://tool.lu/html

  8. 小尾巴 王者   小尾巴   博主

    test

    1. 枫叶 黄金   枫叶  
      @ 小尾巴

      我就是来试试这个小艾特哈,很缺这个功能。@(吐舌)

      1. 小尾巴 王者   小尾巴   博主
        @ 枫叶

        热烈欢迎~

        1. 枫叶 黄金   枫叶  
          @ 小尾巴

          但是我特么好像木有成功。你这个教程。。。不知道哪里出问题呀@(惊哭)

    2. 小尾巴 王者   小尾巴   博主
      @ 小尾巴

      test again