最近访客
uuu1354134的头像-狐狸库
uuu1354134
百度未收录

WordPress博客评论可见实现方法

 

WordPress博客评论可见实现方法-狐狸库
wordpress

之前帮别人测试评论可见功能,并在上一篇文章《WordPress前台编辑器加上字数统计功能》中试用一下,感觉还是很不错的实用功能,可以增加一下访客的评论积极性,也可能会增加一大堆无用的垃圾留言,在论坛上很常见的功能,用多了可能让人产生厌恶。不过很多童鞋对此很感兴趣,所以把实现方法贴过来。

首先推荐一款实现该功能的插件:easy2hide

使用方法,启用插件后,在编辑文章时加入:

<!--easy2hide start{reply_to_this=true}-->一些隐藏内容<!--easy2hide end-->  

下面再说说不用插件的实现方法

原始代码有个缺点即使是博主或者站长,也需要评论之后才能够看到隐藏的内容,所以又有人对该代码进行了改进。代码具体出处未知,有人认领请告知。

把下面代码加到主题functions.php文件中:

function reply_to_read($atts, $content=null) {   
        extract(shortcode_atts(array(\"notice\" => \'<p class=\"reply-to-read\">温馨提示: 此处内容需要<a href=\"#respond\" 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 = \"xxx@aaa.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(\'reply\', \'reply_to_read\');  

自行修改其中的博主Email地址。

使用方法,编辑文章时添加:

[@reply]评论可见的内容[@/reply]  

或者

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

提示:使用时去掉其中的@

温馨提示: 本文最后更新于2022/10/25 11:54:30。若文章内容或图片失效,请 留言联系站长反馈!
!
也想出现在这里? 联系我们
创意广告
© 版权声明
THE END
点赞0赞赏 分享
评论 共1条

请登录后发表评论

    请登录后查看评论内容