wordpress免插件设置回复后可见

作者:matrix 发布时间:2014 年 1 月 26 日 分类:Wordpress

WordPress是可以像论坛那样设置回复可见。代码也不需要多少

仿DZ效果:

仿DZ效果

步骤:

1.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));//notice默认值     
        $email = null;     
        $user_ID = (int) wp_get_current_user()->ID;     
        if ($user_ID > 0) {  
            $email = get_userdata($user_ID)->user_email;  
            $admin_email = "XXXX@email.tk"; //博主Email  
            if ($email == $admin_email) {//若是博主则直接显示内容  
                return '<p class="reply-to-read" style="background:no-repeat">'.$content.'</p>';  
            }  
        } else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {  
            $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);  
        } else {  
            return strpos($notice,'提示: 此处内容需要')  ? $notice : '<p class="reply-to-read" title="此处内容需要评论本文后才能查看.">提示: '.$notice.'</p>';//未检测到评论信息(昵称、网站等)。不是博主,且未评论  
        }  
        if (empty($email)) {  
            return 'TEST CODE:111'.$notice;//无email  
        }  
        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 '<p class="reply-to-read" style="background:no-repeat">'.do_shortcode($content).'</p>';//若已评论  
        } else {  
            return strpos($notice,'提示: 此处内容需要')  ? $notice : '<p class="reply-to-read" title="此处内容需要评论本文后才能查看.">提示: '.$notice.'</p>';//已评论其他,未评论此文章  
        }  
    }  
    add_shortcode('reply', 'reply_to_read');  

说明:使用前将第10行的email地址改为自己的

阅读剩余部分 »

去论坛干扰码方法

作者:matrix 发布时间:2013 年 3 月 28 日 分类:兼容并蓄

以前经常看《电脑爱好者》,家里也堆了至少有半米高。非常受益啊! 😛 感谢cfan!

电脑爱好者2012第23期

这个去论坛干扰码方法  来自 电脑爱好者第2012/23期 未经过实测。值得一试 ➡

(文|郭烨) 阅读剩余部分 »