吾爱汇站网官方联系方式

工作时间: 周一到周五早上09:00-11:00, 下午03:00-05:00, 晚上20:30-22:30(周六、日休息)
QQ: 211985957  168528823  97147700  53150916 汇聚、帮助、交流   E-Mail: postmaster@5ihz.cn
用户交流QQ群
1群21532443 2群413446685 ←提醒:请勿重复加群,谢谢!(本站提供低价收费技术服务,详情联系在线客服)

免插件实现WordPress文章内容回复可见

[复制链接]
查看14634 | 回复49 | 2018-10-13 14:05:21 | 显示全部楼层 |阅读模式
这个功能类似于Discuz论坛的“回复可见”功能,增加网友间互动的一种方式,以下举两个例子。
实现方式一
将以下代码添加到主题的functions.php文件最后一个?>的前面。
  1. //文章部分内容回复可见
  2. function reply_to_read($atts, $content=null) {
  3. extract(shortcode_atts(array("notice" => '
  4. <span style="color: red;">温馨提示:</span>此处内容需要评论本文后刷新才能查看!'), $atts));
  5. $email = null;
  6. $user_ID = (int) wp_get_current_user()->ID;
  7. if ($user_ID > 0) {
  8. $email = get_userdata($user_ID)->user_email;
  9. //对博主直接显示内容
  10. $admin_email = "xxxxx@qq.com"; //博主Email,直接对博主显示而不需要评论!
  11. if ($email == $admin_email) {
  12. return $content;
  13. }
  14. } else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
  15. $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
  16. } else {
  17. return $notice;
  18. }
  19. if (empty($email)) {
  20. return $notice;
  21. }
  22. global $wpdb;
  23. $post_id = get_the_ID();
  24. $query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
  25. if ($wpdb->get_results($query)) {
  26. return do_shortcode($content);
  27. } else {
  28. return $notice;
  29. }
  30. }
  31. add_shortcode('reply', 'reply_to_read');
复制代码
PS:将上面代码中的xxxxx@qq.com替换为站点管理员的邮箱地址,以实现管理员直接可见。
使用方法:{reply}测试隐藏内容是否成功{/reply}
{}改成[],所有符号英文字符
实现方式二
核心代码,添加到主题functions.php中
  1. function hide($atts,$content=null,$code=""){
  2. extract(shortcode_atts(array("reply_to_this"=>'true'),$atts));
  3. global $current_user;
  4. get_currentuserinfo();
  5. if($current_user->ID) $email = $current_user->user_email;
  6. if($reply_to_this=='true'){
  7. if($email){
  8. global $wpdb;
  9. global $id;
  10. $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_author_email = '".$email."' and comment_post_id='".$id."'and comment_approved = '1'");
  11. }
  12. if(!$comments) $content = '<div class="hide_notice">抱歉,只有<a href="'.wp_login_url(get_permalink()).'" rel="nofollow">登录</a>并在本文发表评论才能阅读隐藏内容</div>';
  13. }else{
  14. if($email){
  15. global $wpdb;
  16. global $id;
  17. $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_author_email = '".$email."' and comment_approved = '1'");
  18. }
  19. if(!$comments) $content = '<div class="hide_notice">抱歉,只有<a href="'.wp_login_url(get_permalink()).'" rel="nofollow">登录</a>并在本站任一文章发表评论才能阅读隐藏内容</div>';
  20. }
  21. if($comments) $content = '<div class="unhide"><div class="info">以下为隐藏内容:</div>'.$content.'</div>';
  22. return $content;
  23. }
  24. add_shortcode('hide','hide');
复制代码
CSS样式
里面有个图片链接需要自己去扒一图片加上去
  1. .hide_notice{overflow:hidden;padding:8px 8px 8px 24px;border:1px dashed #ff9a9a;background:url(这里是小锁的图片链接,自己扒一下吧...) no-repeat 6px 50%;font-size:12px;color:#ff0000;margin-bottom:15px}
  2. .hide_notice a{color:#ff4b4b}
  3. .unhide{padding:8px;border:1px dashed #ff9a9a;margin-bottom:15px}
  4. .unhide .info{font-size:12px;color:#ff0000}
复制代码
使用方法:
当前文章回复可见:{hide reply_to_this=”true”}测试隐藏内容是否成功{/hide}
任一文章回复可见:{hide reply_to_this=”false”}测试隐藏内容是否成功2{/hide}
{}改成[],所有符号英文字符

回复

使用道具 举报

你是个笨蛋吗吗 | 2018-10-13 14:26:35 | 显示全部楼层
顶起出售广告位
回复 支持 反对

使用道具 举报

尐安逸丶 | 2018-10-13 21:01:19 | 显示全部楼层
沙发位出租,有意请联系电话:13838384381
回复 支持 反对

使用道具 举报

﹌ 花瓣雨 | 2018-10-14 07:12:00 | 显示全部楼层
广告位,,坐下看看
回复 支持 反对

使用道具 举报

水之音律123 | 2018-10-14 08:20:26 | 显示全部楼层
沙发???
回复 支持 反对

使用道具 举报

风轻云淡 | 2018-10-14 10:16:28 | 显示全部楼层
鼎力支持!!
回复 支持 反对

使用道具 举报

三无先森 | 2018-10-14 10:50:26 | 显示全部楼层
OMG!介是啥东东!!!
回复 支持 反对

使用道具 举报

蛋疼是一种过程 | 2018-10-14 12:02:20 | 显示全部楼层
占位编辑
回复 支持 反对

使用道具 举报

少林派米奇 | 2018-10-14 12:08:06 | 显示全部楼层
无论是不是沙发都得回复下
回复 支持 反对

使用道具 举报

三千飞雪 | 2018-10-14 16:06:55 | 显示全部楼层
非常好,顶一下
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则