智慧广西 · 遨游在电商知识的海洋

  • 首页
  • 知识
    • 装机优化|电脑维护
    • 电商课件|美工运营
  • 资源
    • 电商货源
    • 软件
    • 素材
    • 插件
  • 登录注册
  • 找回密码/退出登录
  1. 首页
  2. 知识
  3. 建站运维|选购建议
  4. 正文

wordpress如何实现文章评论或回复可见

2023年7月15日 282点热度 0人点赞 0条评论

现在来说说如何实现wordpress的文章内容评论后可见吧?其实实现起来很简单,利用wordpress的短代码功能即可实现,代码如下:

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 = "www@wpabc.net"; //博主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');

只需要将以上代码加入到当前使用的主题的functions.php文件里即可。
使用方法:

在编辑文章时插入以下代码即可隐藏内容
[reply]我是被隐藏的内容[/reply](推荐用这种方法)
当然还可以自定义提示回复信息,短代码如下:
[reply notice="回复后才显示哟"]我是被隐藏的内容[/reply]

默认效果如下:

温馨提示:此处内容已隐藏,回复后刷新页面即可查看!

加入自定义提示后,效果如下:

回复后才显示哟
↓↓↓扫下方二维码与我合作↓↓↓

标签: 暂无
最后更新:2023年7月18日

Moon

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

您需要 登录 之后才可以评论

COPYRIGHT © 2022 智慧容县. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

桂ICP备16001541号-2

close
会员购买 你还没有登录,请先登录
  • ¥3 VIP-1个月
  • ¥10 VIP-半年
  • ¥30 VIP-1年
  • ¥50 至尊VIP
在线支付 激活码

立即支付
微信支付
请使用 微信 扫码支付
登录
注册|忘记密码?