WordPress网站建设宣传图片

WordPress设置文章部分内容回复可见

释放双眼,带上耳机,听听看~!

WordPress设置文章部分内容回复可见方法:

方法一:添加代码

代码

将下述代码添加到主题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 = "feng@www.linfengnet.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;     
        }     
    }

代码中的feng@www.linfengnet.com请改为你的管理员邮箱,直接对该邮箱的用户展示内容。

注意添加代码的时候不要加在其他代码的中间,放最底部即可。

functions.php文件位置:

wordpress-functions.php文件位置

调用

在可视化或者编辑框下输入短代码(+符号是为了避免和当前主题段代码冲突,正常使用请删除):

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

或者是添加如下代码:

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

方法二:使用插件

插件名称:Easy2Hide

插件下载地址:easy2hide – WordPress plugin | WordPress.org

插件安装使用:

1、下载Easy2Hide插件上传到/wp-content/plugins/下的文件夹,或者在后台在线插件搜索Easy2Hide直接点击安装即可。

2、安装后切换到后台:插件->已安装的插件,选择Easy2Hide启动插件即可使用。

3、我们在编写文章的时候,只需要在需要隐藏的内容前面加上,后面加上 ,如下所示,只需要选中需要隐藏的内容点击easy2hide即可。

wordpress文章发布

结语:上述就是WordPress设置文章部分内容回复可见的方法分享,可以看到非常简单,而且现在部分wordpress也自带这样的功能,网站使用回复可见可以增加网站的活跃度和一定程度的避免资源被随意采集等情况,不过也要注意使用,避免对正常用户造成影响。

给TA打赏
共{{data.count}}人
人已打赏
WordPress与SEOWordPress技巧

WordPress文章自动生成随机阅读量(点击数)方法

2022-6-4 16:06:20

WordPress技巧

WordPress配置ssl后只有首页301跳转(Apache)解决方法

2022-6-23 19:57:43

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
展开目录