在wordpress中实现内容回复可见代码

chen'mo
2013-02-23 / 0 评论 / 2,399 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于1970年01月01日,已超过19832天没有更新,若内容或图片失效,请留言反馈。

回复可见大家都比较熟悉,DZ很多帖子都设置了内容回复可见,尤其是主题发布,用这种方法骗回复其实还是可以的。WP中也是可以实现的,原理就是用cookies,短代码的形式。直接把下面的代码扔到function.php里就OK乐。当然,你也可以加个小小的样式,样式我就不写了。。

function reply_to_read($atts,$content=null){
    extract(shortcode_atts(array("notice"=>'<span>此处内容需要
<a href="'. get_permalink().'#respond" title="评论本文">评论本文</a>后
<a href="javascript:window.location.reload();" 
title="刷新">刷新本页</a>才能查看.</span>'),$atts));
    $email=null;
    $user_ID=(int)wp_get_current_user()->ID;
    if($user_ID>0){
        $email =  get_userdata($user_ID)->user_email; 
    }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 $content; 
    }else{
        return $notice;
    }
}

add_shortcode('reply', 'reply_to_read');


使用就非常简单了,直接[reply]你要隐藏的内容[/reply]

来源:http://ceezi.com/archives/1001.html

0
wordpress SEO 设置方法
« 上一篇 02-23
用php实现百度网盘直链的代码分享
下一篇 » 02-25

评论 (0)

插入图片