释放双眼,带上耳机,听听看~!
[mom-cs]这个就不废话了,作者主题自带有这个功能,但跟登录可见/付费/回复可见这些功能共用一个代码,这样造成一篇文章里想使用多个功能都不能,遂咱自己使用其他代码代替,好腾出主题功能用来做更好的选择[/mom-cs]
教程如下:依然在functions.php文件里添加如下代码即可搞定:
//评论回复可见
function need_reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '<div style="text-align:center;border:1px dashed #0395f6;padding:8px;margin:10px auto;color:#000000;border-radius: 5px;
<span class="need_reply-to-read"=""><i class="b2font b2-face"></i>温馨提示<i class="b2font b2-face"></i> <p>此处内容需要 <a href="#respond" title="评论本文">评论本文</a> 后 <a href="javascript:window.location.reload();" target="_self">刷新本页</a> 才能查看!</p></div>'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//对博主直接显示内容
$admin_email = "*****@qq.com"; //管理员的Email
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('need_reply', 'need_reply_to_read');
//添加按钮
add_action('after_wp_tiny_mce', 'my_quicktags');
function my_quicktags($mce_settings) {
?>
<script type="text/javascript">
QTags.addButton( 'reply', '评论可见', '{need_reply}', '[/need_reply]' );
function my_quicktags() {
}
</script>
<?php
}
[mom-sb]提示:在38行代码处,将{}换成[][/mom-sb]