zishu's blog

zishu's blog

一个热爱生活的博主。https://zishu.me

Typecho comment reply @ comment person

By default, Typecho does not have the functionality to mention (@) the commenter in comments. You can add the following code to enable it.

In functions.php:

/*
* Reply to comments with @ mention
*/
function get_comment_at($coid)
{
    $db   = Typecho_Db::get();
    $prow = $db->fetchRow($db->select('parent,status')->from('table.comments')
        ->where('coid = ?', $coid));
    $mail = "";
    $parent = @$prow['parent'];
    if ($parent != "0") {
        $arow = $db->fetchRow($db->select('author,status,mail')->from('table.comments')
            ->where('coid = ?', $parent));
        @$author = @$arow['author'];
        $mail = @$arow['mail'];
        if(@$author && $arow['status'] == "approved"){
            if (@$prow['status'] == "waiting"){
                echo '<p class="commentReview">(Comment under review)</p>';
            }
            echo '<a href="#comment-' . $parent . '">@' . $author . '</a>';
        }else{
            if (@$prow['status'] == "waiting"){
                echo '<p class="commentReview">(Comment under review)</p>';
            }else{
                echo '';
            }
        }

    } else {
        if (@$prow['status'] == "waiting"){
            echo '<p class="commentReview">(Comment under review)</p>';
        }else{
            echo '';
        }
    }
}

Then, add the following code before the output of the comment content in comments.php:

<?php $parentMail = get_comment_at($comments->coid)?><?php echo $parentMail;?>

▼ Code example
1654569311759.png

▼ Result
1654569512094.png


My blog will soon be synchronized to Tencent Cloud+ Community. I invite everyone to join: https://cloud.tencent.com/developer/support-plan?invite_code=17ctk6evsjk5b

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.