多语言展示
当前在线:1185今日阅读:61今日分享:18

wordpress 不用插件实现类似论坛的回复后查看

在wordpress 中不使用插件来实现评论后才可以查看!类似于网站论坛中的hide功能
工具/原料
1

wordpress 程序搭建的网站

2

一段php代码

方法/步骤
1

需要代码////回复可见/////function reply($content){      if (preg_match_all('/([\s\S]*?)/i', $content, $hide_words)){      $stats = 'hide';      global $current_user;      get_currentuserinfo();       if ($current_user->ID) {          $email = $current_user->user_email;      } else if (isset($_COOKIE['comment_author_email_'.COOKIEHASH])) {          $email = $_COOKIE['comment_author_email_'.COOKIEHASH];      }       $ereg = "^[_\.a-z0-9]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,5}$";      if (eregi($ereg, $email)) {          global $wpdb;          global $id;          $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_author_email = '".$email."' and comment_post_id='".$id."'and comment_approved = '1'");          if ($comments) {              $stats = 'show';          }      }       $admin_email = "4531289@qq.com"; //博主Email,博主直接查看      if ($email == $admin_email) {          $stats = 'show';          }           $hide_notice = '

温馨提示:此处内容需要评论本文后,刷新本页才能查看。
';          if( $stats == 'show' ){              $content = str_replace($hide_words[0], $hide_words[1], $content);          }else{              $content = str_replace($hide_words[0], $hide_notice, $content);          }      }      return $content;  }  add_filter('the_content', 'reply');

2

打开你的wordpress后台,

3

找到外观下的编辑菜单,找到右侧的funtion.php

4

点击打开,然后把上面的代码黏贴到function.php的最后

5

然后点击更新,在发表博文,在你想要隐藏的某部分内容中加入你要隐藏的内容

6

最后发布博文,就ok了

注意事项

第五步需要你使用代码模式中输入

推荐信息