Typecho 评论 @ 父级用户名

这鸟毛东西不知道怎么加到评论内容 <p> 里面最前面,只能将就用了。

functions.php 里加

function at_parent_comment($coid){
    $db   = Typecho_Db::get();
    $row = $db->fetchRow($db->select('parent')->from('table.comments')->where('coid = ? AND STATUS = ?', $coid, 'approved'));//当前评论
    if(isset($row['parent'])){//有父级
        $parent = $row['parent'];
        if ($parent != "0"){
            $prow = $db->fetchRow($db->select('author','mail','text','status')->from('table.comments')->where('coid = ?', $parent));
            $pauthor = $prow['author'];
            $pmail = $prow['mail'];
            $ptext = $prow['text'];
            if($pauthor){
                if($prow['status'] == "approved"){
                    return '<a href="#comment-' . $parent . '" class="at">@' . $pauthor . '</a>';
                }elseif($prow['status'] == "waiting"){
                    return '<p>(评论审核中)</p>';
                }else{
                    return '';
                }
            }
        }
    }
}

在 comments.php 原来显示评论的代码处 替换

<?php echo at_parent_comment($comments->coid) . $comments->content; ?>

@父级用户名并带出父级评论内容

function getCommentHF($coid){
    $parser = new HyperDown(); //Typecho内置函数 将md转为html
    $db   = Typecho_Db::get();
    $prow = $db->fetchRow($db->select('parent')
        ->from('table.comments')
        ->where('coid = ? AND status = ?', $coid, 'approved'));
    if (isset($prow['parent'])){
        //origin start
        $parent = $prow['parent'];
        if ($parent != "0") {
            $arow = $db->fetchRow($db->select('text','author','status')
                ->from('table.comments')
                ->where('coid = ?', $parent));
            $text = $arow['text'];
            $author = $arow['author'];
            $status = $arow['status'];
            if($author){
                if($status=='approved'){
                    $href   = '<blockquote><a class="comment_a_link_fixer" href="#comment-' . $parent . '">@'.$author.'</a><br>'.$parser->makeHtml($text).'</blockquote>';;
                }else if($status=='waiting'){
                    $href   = '<a>评论审核中···</a>';
                }
            }
            echo $href;
        } else {
            echo "";
        }
        //origin end
    }
}

via: //shangjixin.com/archives/typecho-cancel-taowa.html

换色
阅读
登录
扫码