前言
7b2的seven主题没有自带隐藏内容评论可见,对于我们这种小博主来说是件很头疼的事,没有评论就没有更新的动力,同时,据说评论对seo会有所帮助,博主百度了大量的方法后在seven主题中尝试均没有效果,会出现各种问题,各种报错,前两天沃茨博客博主给我发了一段他之前用过的代码,我在此之上,修改了css样式,分享给大家,经过测试,seven主题并未出现啥报错,代码也适用于其他Wordpress主题。
教程
首先我们需要将以下代码放到主题根目录下的functions.php文件内
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '
温馨提示: 此处内容需要评论后刷新才能查看
去评论 刷新本页
.'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//对博主显示内容
$admin_email = "1965467534@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 do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode('cm', 'reply_to_read');
将里面的邮箱改为自己的管理员邮箱,同时以上可以引用阿里巴巴矢量图标,大家可以自行尝试
接下来把css放入style.css文件内即可
/*评论刷新可见*/
.Hreply {
margin-bottom: 20px;
border: 1px dashed #ddd;
padding-bottom: 25px;
background-color: #fafafa;
}
.HreplyBefore{
position: relative;
top: -18px;
left: 0;
height: 13px;
width: 100%;
justify-content: center;
text-align: center;
}
.HreplyBefore i{
font-size: 24px;
color: #ec1206;
background: #fff;
position: relative;
padding: 0 20px;
}
.Hreply .replyinfo{margin:0 auto}
.Hreply .reply-to-read{text-align:center;margin-top:5px;margin-bottom:12px;color: #ff6a6a;}
.Hreply .GoReply{position: relative;text-align: center;}
.Hreply .GoReply a{
padding:5px 16px;
background:#0c8df9;
color:#fff;
background: linear-gradient(to left,#70a4fe,#4583ec);
}
最后在编辑文本的时候添加段代码(cm)(/cm)即可,值得注意,请将()改为[]
还有就是第三方登录不可使用
不行啊,网站都打不开了