代码如下:
<?php
/**
* get recent comments
* @param unknown_type $args
* @return unknown_type
*/
function DeamworkRecentcomments($args='number=5&status=approve'){</p> <p> $cacheID = md5($args);
//有缓存就直接输出
if($output = wp_cache_get('recentComments_'.$cacheID, 'Winysky')){
echo $output;
return;
}</p> <p> //$rcms = get_comments($args);
global $wpdb;</p> <p> $my_email = "'" . get_bloginfo ('admin_email') . "'";
//自动获取博主邮箱
$rcms = $wpdb->get_results("
SELECT ID, post_title, comment_ID, comment_author, comment_author_email, comment_content
FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts
ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
WHERE comment_approved = '1'
AND comment_type = ''
AND post_password = ''
AND comment_author_email != $my_email</p> <p>ORDER BY comment_date_gmt
DESC LIMIT 10</p> <p>");</p> <p> //print_r($rcms);return;
if(empty($rcms)){
_e('没有数据');
return;
}
//历遍数据
$output = '';
foreach( $rcms as $rcm ){
$author = $rcm->comment_author;
//if($author =='admin'){continue;}
$content = DeamworkStriptags( $rcm->comment_content);
$the_title = get_the_title($rcm->comment_post_ID);
$s_excerpt = convert_smilies( DeamworkSubstr( $content, 200 ) );
$contents = '<span class=\'recentcommentslink_author\'>' . $author . '</span> <span class=\'recentcommentslink_on\'>on</span> <span class=\'recentcommentslink_title\'>' . $the_title . '</span><div class=\'recentcommentslink_excerpt\'>' . get_avatar($rcm->comment_author_email, 64). $s_excerpt . '</div>';</p> <p> $output .= '<li><div id="C_' . $rcm->comment_ID . '_d" style="display:none">' . $contents . '</div>' . '<a id="C_' . $rcm->comment_ID . '" class="recentcommentslink" >' . get_avatar($rcm->comment_author_email, 32) . '</a></li>';</p> <p> }
//输出后加入缓存
wp_cache_add('recentComments_'.$cacheID,$output, 'Deamwork');
echo $output;
}
<?php
/**
* get recent comments
* @param unknown_type $args
* @return unknown_type
*/
function DeamworkRecentcomments($args='number=5&status=approve'){</p> <p> $cacheID = md5($args);
//有缓存就直接输出
if($output = wp_cache_get('recentComments_'.$cacheID, 'Winysky')){
echo $output;
return;
}</p> <p> //$rcms = get_comments($args);
global $wpdb;</p> <p> $my_email = "'" . get_bloginfo ('admin_email') . "'";
//自动获取博主邮箱
$rcms = $wpdb->get_results("
SELECT ID, post_title, comment_ID, comment_author, comment_author_email, comment_content
FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts
ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
WHERE comment_approved = '1'
AND comment_type = ''
AND post_password = ''
AND comment_author_email != $my_email</p> <p>ORDER BY comment_date_gmt
DESC LIMIT 10</p> <p>");</p> <p> //print_r($rcms);return;
if(empty($rcms)){
_e('没有数据');
return;
}
//历遍数据
$output = '';
foreach( $rcms as $rcm ){
$author = $rcm->comment_author;
//if($author =='admin'){continue;}
$content = DeamworkStriptags( $rcm->comment_content);
$the_title = get_the_title($rcm->comment_post_ID);
$s_excerpt = convert_smilies( DeamworkSubstr( $content, 200 ) );
$contents = '<span class=\'recentcommentslink_author\'>' . $author . '</span> <span class=\'recentcommentslink_on\'>on</span> <span class=\'recentcommentslink_title\'>' . $the_title . '</span><div class=\'recentcommentslink_excerpt\'>' . get_avatar($rcm->comment_author_email, 64). $s_excerpt . '</div>';</p> <p> $output .= '<li><div id="C_' . $rcm->comment_ID . '_d" style="display:none">' . $contents . '</div>' . '<a id="C_' . $rcm->comment_ID . '" class="recentcommentslink" >' . get_avatar($rcm->comment_author_email, 32) . '</a></li>';</p> <p> }
//输出后加入缓存
wp_cache_add('recentComments_'.$cacheID,$output, 'Deamwork');
echo $output;
}
最后,试试效果吧~
标签:WordPress
相关阅读 >>
wordpress优化头部 去掉版权等信息 wordpress去掉generator
更多相关阅读请进入《wordpress》频道 >>
相关推荐
评论
管理员已关闭评论功能...
- 欢迎访问木庄网络博客
- 可复制:代码框内的文字。
- 方法:Ctrl+C。