wordpress在实际运营的过程中往往需要用到很多功能,在能不安装插件的情况下本来还是不喜欢安装插件,可以通过PHP来实现回复可见的功能新增
添加教程
首先进入wordpress后台 ->> 外观 ->> 主题文件编辑器,选择当前启用主题下的functions.php文件
将如下代码添加进functions.php中即可实现回复可见
添加如下代码:
function reply_to_read($atts,$content=null){ extract(shortcode_atts(array("notice"=>'<span class="reply-to-read" style="font-size:16px; letter-spacing:3px; font-weight:bold; background-color:#f7f7f7; padding:10px;text-align: center;width:100%; color:#272727; border-radius:8px; border-style:dotted; border-width:2px; border-color:#959595; display:block;">此处内容需要<a style="color:#f5365c;" href="'. get_permalink().'#respond" title="评论本文">评论本文</a>后<a style="color:#f5365c;" href="javascript:window.location.reload();" title="刷新">刷新本页</a>才能查看.</span>'),$atts)); $email=null; $user_ID=(int)wp_get_current_user()->ID; if($user_ID>0){ $email = get_userdata($user_ID)->user_email; $admin_email = "1240312603@qq.com"; if ($email == $admin_email) { return $content; } }else if(isset($_COOKIE['comment_author_email_'.COOKIEHASH])){ $email=str_replace('%40','@',$_COOKIE['comment_author_email_'.COOKIEHASH]); }else{ return $notice; } if(empty($email)){ return $notice; } global $wpdb; $post_id=get_the_ID(); $query="SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1"; if($wpdb->get_results($query)){ return $content; }else{ return $notice; } } add_shortcode('reply', 'reply_to_read');
|
短代码填写规范
[reply]你希望评论回复可见的内容[/reply]
|
实现效果如下
