wordpress,非插件實現文章內容回復可見的代碼分享
作者:焚花祭秋 / 发布时间:September 27, 2011 / 分类:博客.技巧 / 2 Comments
隱藏內容回復可見,一個比較有意思的功能,對於很多人來說可能在論壇遇到的情況比較多,沒想到在研究的過程中才發現,原來強大的Wordpress也能實現,如果有需要的朋友可以直接享用了,嘿嘿,老規矩,感謝代碼的書寫者亂了感覺,希望大家多多支持,多多喜歡!
在主題的function.php中加入一下代碼即可:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | function reply_to_read($atts,$content=null){ extract(shortcode_atts(array("notice"=>'<span class="reply-to-read">此處內容需要 <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; //如果用戶已登錄,從登錄信息中獲取email }else if(isset($_COOKIE['comment_author_email_'.COOKIEHASH])){ $email=str_replace('%40','@',$_COOKIE['comment_author_email_'.COOKIEHASH]); //如果用戶未登錄但電腦上有本站的Cookie信息,從Cookie裏讀取email }else{ return $notice; //無法獲取email,直接返回提示信息 } if(empty($email)){ return $notice; } global $wpdb; $post_id=get_the_ID(); //文章的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](去掉@即可),搞定,Over,收工!
悦听有声,路过看看
简繁转换功能在也没刷新下会失效
好东西 谢谢分享先收藏一下下 ...
主题蛮好看的,好像轻博客一样
不错呀
不错哦 收藏了