想着以后可能分享的资源会越来越多,于是去找看有没有WordPress评论才可查看隐藏内容的设置方式,这样也能增加一下访客的评论积极性,方法是从知更鸟那找打的,所以简单做个实验,文章《商业摄影汽车布光以及修图视频教程》查看效果
方法1
插件:easy2hide??
方法2
我一般是能用代码就不用插件的人,因为不管是更换更新主题还是搬家都是比较方便的!
纯代码实现,把下面代码加到主题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('{f8c0b8912c221657a509e899bb88015452895b42f58a46f0cac7b29b4b597b88}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]
提示:使用时去掉其中的@
之前我也曾想弄一个隐藏的插件,经过深思熟滤还是放弃了,既然是分享就彻底一点,裸着来吧
留着 以后用
昨晚也来过啦,但是太晚就没留言了
這功能對論壇還挺實用, 但對於博客似乎沒什麼用
嗯是的
对于技术类博客来说,隐藏插件还是蛮不错的选择
嗯