王尘宇王尘宇

研究百度干SEO做推广变成一个被互联网搞的人

wordpress复兴可见的完成要领

说到这个wordpress复兴可见的功用,小编早在多年前就尝试过,然则会有一些问题,比方运用多说致使复兴后,不能马上显现内容,所以就取消了这个功用,然则如果是用wordpress自带批评模块的话,那末这个功用,可谓是秒回秒可见哈!

下面我们直接说教程

这块,我就不引荐人人用什么插件了。完整到场代码即可OK!

wordpress主题文件的functions.php内到场以下代码:

  1. function reply_to_read($atts, $content=null) {     

  2.         extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提醒: 此处内容须要<a href="#respond" title="批评本文">批评本文</a>后才检察.</p>'), $atts));     

  3.         $email = null;     

  4.         $user_ID = (int) wp_get_current_user()->ID;     

  5.         if ($user_ID > 0) {     

  6.             $email = get_userdata($user_ID)->user_email;     

  7.             //对博主直接显现内容     

  8.             $admin_email = "[email protected]"; //博主Email     

  9.             if ($email == $admin_email) {     

  10.                 return $content;     

  11.             }     

  12.         } else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {     

  13.             $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);     

  14.         } else {     

  15.             return $notice;     

  16.         }     

  17.         if (empty($email)) {     

  18.             return $notice;     

  19.         }     

  20.         global $wpdb;     

  21.         $post_id = get_the_ID();     

  22.         $query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";     

  23.         if ($wpdb->get_results($query)) {     

  24.             return do_shortcode($content);     

  25.         } else {     

  26.             return $notice;     

  27.         }     

  28.     }     

  29.       

  30.     add_shortcode('reply', 'reply_to_read');   

将代码里的邮箱替代成我们本身的,增加好后,保留即可!

以后我们在编写文章的时刻就能够增加短代码来完成wordpress复兴可见的功用了!

  1. [@reply]批评可见的内容[@/reply]    

或许

  1. [@reply notice="自定义的提醒信息"]批评可见的内容[@/reply]    

人人注意下,小编为了让代码展示出来,在代码里加了@,人人在运用的时刻把@去掉!functions.php内的代码仅替代邮箱即可!!!

相关文章

评论列表

发表评论:
验证码

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。