欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」WordPress设置文章部分内容回复可见方法

作者 : 自学哈 本文共1053个字,预计阅读时间需要3分钟 2022-10-20 共244人阅读
也想出现在这里? 联系我们

为活跃网站交流氛围,需要给WordPress网站设置文章部分内容回复后,可以使用代码和插件来实现。

一,WordPress回复可见代码

打开所用主题的functions.php文件,加入以下代码:

//评论可见
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提示: 此处内容需要<a href="#respond" rel="external nofollow"  title="评论本文">评论本文</a>后才能查看.</p>'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;

//对博主直接显示内容
$admin_email = "admin@www.24mh.cn";
//博主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;
}
}

将上面代码中邮箱换成站长自己的邮箱,保存文件即可。

二,WordPress回复可见

使用插件比较简单。

登录WordPress后台,在插件安装界面,搜索安装“Easy2Hide”插件,启用即可。

本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」WordPress设置文章部分内容回复可见方法
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号