打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
WordPress文章回复评论才可见内容

WordPress文章回复评论才可见内容 

在Discuz等论坛经常会看到:"该帖子需要回复后才能看到”,“本链接需要回复才能下载”,“如果您要查看本帖隐藏内容请先回复”。

这个功能假如能移植到wordpress是很羡慕的。与Discuz论坛相对而言,Wordpress是很开放的,文章除了密码保护外,文章内容是可以随便查看。

给Wordpress文章增加回复可见,既可防止采集党的肆意转载,保护原创;又可提高互动,增加留言,提高人气等。

1、在 functions.php 中添加下面的代码

  1. //文章内容回复可见
  2. add_shortcode('reply', 'reply_to_read');
  3.  
  4. function reply_to_read($atts, $content=null) {
  5. extract(shortcode_atts(array("notice" => '<p>温馨提示:此处内容需要<a href="#respond" title="评论本文">评论本文</a>后才能查看。</p>'), $atts));
  6. $email = null;
  7. $user_ID = (int) wp_get_current_user()->ID;
  8. if ($user_ID > 0) {
  9. $email = get_userdata($user_ID)->user_email;
  10. //对博主直接显示内容
  11. $admin_email = "server-c@qq.com"; //<span style="color: #0000ff;">博主Email</span>
  12. if ($email == $admin_email) {
  13. return $content;
  14. }
  15. } else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
  16. $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
  17. } else {
  18. return $notice;
  19. }
  20. if (empty($email)) {
  21. return $notice;
  22. }
  23. global $wpdb;
  24. $post_id = get_the_ID();
  25. $query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
  26. if ($wpdb->get_results($query)) {
  27. return do_shortcode($content);
  28. } else {
  29. return $notice;
  30. }
  31. }

其中,博主的EMail设置自己的(上面红色标注),博主可以不用回复就可见。

2、在 style.css 中添加上面代码的显示效果

非必需的,可以不添加,这是CSS样式,可以自己定制样式。。。

  1. .reply-to-read{
  2. background: #CCCCCC;
  3. color: #000000;
  4. font-family: "Microsoft YaHei","微软雅黑","幼圆","宋体","楷体","楷体_GB2312";
  5. font-size: 16px;
  6. font-weight:bold;
  7. font-style: normal;
  8. margin:0;
  9. padding: 10px 20px;
  10. line-height: normal;
  11. }

3、代码使用方法

将需要隐藏的内容用[reple]包裹,编辑文章时,添加:

  1. [reply]你希望评论回复可见的内容[/reply]

  1. [reply notice="自定义提醒回复内容"]自定义提醒回复内容[/reply]

效果跟你看到的论坛的一样,只是样式可以自己用css定义(步骤2)。

 

转自:随意博客

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
wordpress纯代码实现“隐藏内容评论后可见”功能效果
wordpress评论回复自动发邮件的功能
10条技巧帮你精简WordPress网站后台
WordPress如何批量修改旧文章的别名为文章ID
WordPress 技巧:给每个页面都设置不同的菜单
WordPress主题制作导航的N种方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服