分类:折腾日期:2012-02-27 - 18:15:33评论:20条作者:老谢
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'); |
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');
以上代码复制到function.php即可,用法如下:
原文传送门:http://zuidongting.com/non-plug-ins-to-achieve-the-contents-of-the-article-shows-the-code-reply-share.html
最新评论
zwwooooo:类似以前做网站开发时,一开始有自...
老陳网志:有点高端,像我们整点nas玩玩就够...
springwood:自从 CentOS 不维护之后,我换 U...
大D:难都搞下来了,那就更得YM了
大D:只能是YM了,谢总牛啊
灰常记忆:经济不好 今年我也换了机器 一...
大峰:这是海外服务器嘛?速度挺快的。
大D:只能单走一个6了哈哈哈
zwwooooo:买特斯拉和买iPhone的人群其实相似...
平安家属子痕:一直坚持油车,看你写的心里有...