评论区显示留言格式代码php,WordPress主题文章作者评论区留言高亮显示

当WordPress文章作者在自己的文章中回复读者评论留言时,在名称后面显示“文本作者”提示,可以让读者明确知道是作者亲自回复自己的留言是不是有点小鸡冻呢。

适合多作者的博客网站,单一作者的博客,还是用网上盛传的“管理员“提示更好些。

首先将下面判断文章作者代码添加到当前主题函数模板functions.php中:/**

* 检查指定的评论是否由评论文章的作者撰写。

*

*/

function twentytwenty_is_comment_by_post_author( $comment = null ) {

if ( is_object( $comment ) && $comment->user_id > 0 ) {

$user = get_userdata( $comment->user_id );

$post = get_post( $comment->comment_post_ID );

if ( ! empty( $user ) && ! empty( $post ) ) {

return $comment->user_id === $post->post_author;

}

}

return false;

}

将显示调用代码添加到主题评论模板显示评论者名称代码的后面即可。<?php

$post_author = twentytwenty_is_comment_by_post_author( $comment );

if ( $post_author ) {

echo '文章作者';

}

?>

不同主题评论模板代码不同,具体加到哪个位置,只能自行研究了。

同时显示管理员和作者的调用方法:<?php

if ($comment->comment_author_email == get_option('admin_email')) {

echo '博主';

} else {

$post_author = twentytwenty_is_comment_by_post_author( $comment );

if ( $post_author ) {

echo '作者';

}

}

?>

判断作者代码取自WordPress默认主题Twenty Twenty,默认主题虽然外观看似简单,但功能真的很强大,有很多东西值得挖掘。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值