首页 > SEO优化 > wordpress回复可见的实现方法

wordpress回复可见的实现方法

时间:2023年10月20日 分类:SEO优化 浏览量:89

说到这个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内的代码仅替换邮箱即可!!!

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

标签: