资源描述
【WordPress功能】代码实现评论本文才可见某些文章内容
代码实现WordPress评论文章、回复可见才能见到隐藏内容。 在主题目录下找到functions.php文件,在合适位置添加下方代码
// 评论可见
function reply_to_read($atts, $content=null) {
$html = '<p class="reply-to-read">';
$html.= '<font color="#ff0000">温馨提示: </font>';
$html.= '此处为隐藏内容,需要';
$html.= '<a href="#respond" title="评论本文">评论本文</a>';
$html.= '后才能查看.';
$html.= '</p>';
extract(shortcode_atts(array("notice" => $html), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//对博主直接显示内容
$admin_email = get_userdata($user_ID)->user_email ;//博主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 ";
$query.= "`comment_post_ID`={$post_id} 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');使用方法:
[reply-]需要隐藏的内容[/reply],需要把[reply-]的“-”去掉
资源截图

转载请注明来源地址:小川编程 » https://www.youhutong.com/index.php/article/index/3341.html
1、本站发布的内容仅限用于学习和研究目的.请勿用于商业或非法用途,下载后请24小时内删除。
2、本站所有内容均不能保证其完整性,不能接受请勿购买或下载,如需完整程序,请去其官方购买正版使用
3、本站联系方式Email:admin@youhutong.com ,收到邮件会第一时间处理。
4、如侵犯到任何版权问题,请立即告知本站(立即在线告知),本站将及时删除并致以最深的歉意
