鱼见海资源网最新教程:
现在来说说如何实现wordpress的文章内容评论后可见吧?其实实现起来很简单,利用wordpress的短代码功能即可实现,代码如下:
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 = "www@wpabc.net"; //博主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('reply', 'reply_to_read');
只需要将以上代码加入到当前使用的主题的functions.php文件里即可。
使用方法:
在编辑文章时插入以下代码即可隐藏内容
当然还可以自定义提示回复信息,短代码如下:
回复后才显示哟
注意其中注释了博主E-mail的地方改成你自己的E-mail,这样就可以设置成对站长不隐藏内容了。
文章来源于互联网
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容