> 转载 > WordPress评论回复代码

WordPress评论回复代码

博客上有的资源用easy2hide插件隐藏了,不过我觉得WordPress能不用插件就不用插件,期间试了下乱了感觉的《WP短代码之评论可见》的代码,发现WordPress的短代码里面包含了另一个短代码,好像第二个短代码无效,至少我的博客上是这样,但用easy2hide就可以正常显示。没办法只好自己动手修改代实现无插件代码版。

使用说明:

代码参考:WordPress插件:Login to view all、easy2hide及WP短代码之评论可见

代码还是使用类似easy2hide的标签样式,使用这个标签的好处是,停用本插件后该标签不会被显示出来。使用时切换到编辑器代码模式,直接插入如下代码,把“需要隐藏的内容”改成你自己要隐藏的东东,支持嵌套标签,比如可以配合Hacklog DownloadManager插件使用。

  1. <!--reply start-->需要隐藏的内容<!--reply end--> 

安装方法:

将下面的代码复制到你使用的主题的functions.php最后,并把代码里面的“博主Email”改成你的,实现博主直接查看。

  1. //评论可见代码版 http://www.im1982.com/wordpress-comment-reply-code.html  
  2. function reply($content){  
  3.     if (preg_match_all('/<!--reply start-->([\s\S]*?)<!--reply end-->/i', $content$hide_words)){  
  4.     $stats = 'hide';  
  5.     global $current_user;  
  6.     get_currentuserinfo();  
  7.  
  8.     if ($current_user->ID) {  
  9.         $email = $current_user->user_email;  
  10.     } else if (isset($_COOKIE['comment_author_email_'.COOKIEHASH])) {  
  11.         $email = $_COOKIE['comment_author_email_'.COOKIEHASH];  
  12.     }  
  13.  
  14.     $ereg = "^[_\.a-z0-9]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,5}$";  
  15.     if (eregi($ereg$email)) {  
  16.         global $wpdb;  
  17.         global $id;  
  18.         $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_author_email = '".$email."' and comment_post_id='".$id."'and comment_approved = '1'");  
  19.         if ($comments) {  
  20.             $stats = 'show';  
  21.         }  
  22.     }  
  23.  
  24.     $admin_email = "[email protected]"//博主Email,博主直接查看  
  25.     if ($email == $admin_email) {  
  26.         $stats = 'show';  
  27.         }  
  28.  
  29.         $hide_notice = '<div style="text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;">温馨提示:此处内容需要<a href="'. get_permalink().'#respond" title="评论本文">评论本文</a>后,<a href="javascript:window.location.reload();" title="刷新">刷新本页</a>才能查看。</div>';  
  30.         if$stats == 'show' ){  
  31.             $content = str_replace($hide_words[0], $hide_words[1], $content);  
  32.         }else{  
  33.             $content = str_replace($hide_words[0], $hide_notice$content);  
  34.         }  
  35.     }  
  36.     return $content;  
  37. }  
  38. add_filter('the_content', 'reply');

原文地址:http://www.im1982.com/wordpress-comment-reply-code.html

典型的夜猫子,失眠者。爱好LOL、徒步、旅行、拍照、音乐、小球。E-mail:[email protected]

WordPress评论回复代码:等您坐沙发呢!

发表评论

表情
还能输入210个字

了解 李英杰害虫 的更多信息

立即订阅以继续阅读并访问完整档案。

Continue reading