缙哥哥的博客
与你分享我的点点滴滴生活

WordPress评论回复可见的实现方法

280G全国流量的电信星海卡仅需29元/月,长期可续该套餐,随时可注销

说到这个wordpress回复可见的功能,缙哥哥早在多年前就尝试过,但是会有一些问题,比如使用多说导致回复后,不能立刻显示内容,所以就取消了这个功能,但是如果是用wordpress自带评论模块的话,那么这个功能,可谓是秒回秒可见哈!

下面我们直接说教程吧

这块,我就不推荐大家用什么插件了。完全加入代码即可OK!

在wordpress主题文件的functions文件内加入以下代码:

/**
 * WordPress评论回复可见的实现方法
 * https://www.dujin.org/5680.html
 */
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '
<p class="reply-to-read">温馨提示: 此处内容需要<a title="评论本文" href="#respond">评论本文</a>后才能查看.</p>
'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()-&gt;ID;
if ($user_ID &gt; 0) {
$email = get_userdata($user_ID)-&gt;user_email;
//对博主直接显示内容
$admin_email = "[email protected]"; //博主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-&gt;comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
if ($wpdb-&gt;get_results($query)) {
return do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode('reply', 'reply_to_read');

将代码里的邮箱替换成我们自己的,添加好后,保存即可!

之后我们在编写文章的时候就可以添加短代码来实现wordpress回复可见的功能了!注意,将”>”改为”]”方可实现。

[reply>评论可见的内容[/reply>
[reply notice="自定义的提示信息">评论可见的内容[/reply>

 

赞(3) 打赏
转载请注明来源及链接:缙哥哥 » WordPress评论回复可见的实现方法
如需 WordPress 优化加速、二次开发、托管等服务,可联系我购买付费服务:点此联系我 | 近期站内热门福利:

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册