欢迎光临
我们一直在努力

WordPress如何让文章评论/回复后查看内容

具体实现步骤如下:

1、将以下代码添加到主题的functions.php文件里(PS:将代码中的1449585010@qq.com替换为站点管理员的邮箱地址,以实现管理员直接可见。)

//部分内容回复可见
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '
<span style="color: red;">温馨提示:</span>此处内容需要<a title="评论本文" href="#respond">评论本文</a>后刷新才能查看!
'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//对博主直接显示内容
$admin_email = "1449585010@qq.com"; //博主Email,直接对博主显示而不需要评论!
if ($email == $admin_email) {
return $content;
}
} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
} else {
return $notice;
}
if (empty($email)) {
return $notice;
}
global $wpdb;
$post_id = get_the_ID();
$query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
if ($wpdb->get_results($query)) {
return do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode('reply', 'reply_to_read');

2、在编辑文章的时候,只需要切换到文本模式,在需要隐藏的部分内容中前后加上短代码即可。

[reply]评论可见的内容[/reply]
[reply notice="自定义的提示信息"]评论可见的内容[/reply]
赞(0) 打赏
未经允许不得转载:新起点博客 » WordPress如何让文章评论/回复后查看内容


关注公众号『新起点软件管家』

获取最新网络资源及破解软件!
带你玩转各样软件...

评论 4

评论前必须登录!

 

  1. #-19

    感谢分享,谢谢站长!!

    绿软吧(lvr8)3年前 (2020-11-13)
  2. #-18

    你这个评论并刷新,才能查看的插件是哪一个?

    有来有问3年前 (2021-02-20)
  3. #-17

    感谢分享

    自媒体运营2年前 (2021-12-09)

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏