wordpress免插件设置回复后可见

作者:matrix 被围观: 39,215 次 发布时间:2014-01-26 分类:Wordpress | 68 条评论 »

这是一个创建于 3742 天前的主题,其中的信息可能已经有所发展或是发生改变。

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地址改为自己的

代码来自WordPress 隐藏部分内容 评论后可见

我这稍微美化些

2.style.css中添加:

.reply-to-read {  
overflow: hidden;  
margin: 10px 0;  
padding: 8px 8px 8px 24px;  
border: 1px dashed hsl(0, 100%, 80%);  
background: hsl(0, 100%, 100%) url(http://image.gfan.com/static/image/gfan/locked.gif) no-repeat 6px 50%;  
font-size: 12px;  
zoom: 1;  
}  

说明:
背景图片来自机锋论坛
可以自己本地化:http://www.400gb.com/file/55532828
3.使用的时候输入短代码:(下面的【】分别替换为[]

【reply】隐藏的内容【/reply】

或者

【reply notice=自定义信息】隐藏的内容【/reply】

ps:嫌每次输reply短代码麻烦,可以参考>>

WordPress 3.5.1添加后台编辑器按钮

来添加按钮,方便多了。

这里的话在my-quicktags.js中添加:(下面的【】分别替换为[]
QTags.addButton( 'reply', 'reply回复可见', "\n【reply notice=】", "【/reply】\n" );
测试:

提示: 此处内容需要评论本文后才能查看.

参考:http://www.wpdaxue.com/WordPress-reply-to-view-contents.html

 

其他文章:
本文固定链接:https://www.hhtjim.com/visible-after-reply.html
matrix
本文章由 matrix 于2014年01月26日发布在Wordpress分类下,目前没有通告,你可以至底部留下评论。
转载请注明:wordpress免插件设置回复后可见-HHTjim'S 部落格
关键字:,

有68 条评论 »

  1. 993 993 2022-3-6 1:39:34 +0800#53

    楼主,这个代码失效了没,现在还可以使用吗?

  2. 驱蚊器二 驱蚊器二 2016-12-25 2:12:25 +0800#52

    测试

  3. m78 m78 2016-11-12 22:19:37 +0800#51

    测试

1 4 5 6

添加新评论 »

 🙈 😱 😂 😛 😭 😳 😀 😆 👿 😉 😯 😮 😕 😎 😐 😥 😡 😈 💡

插入图片

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!