wordpress自带的缓存功能使用介绍


当前第2页 返回上一页


代码如下:

<?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

返回前面的内容

相关阅读 >>

docker compose多容器部署的实现

在七牛云存储上部署wordpress站点的教程

能有效改善wordpress cms功能的8个插件分享

wordpress抓取文章第一张远程图片保存到本地的方法

wordpress主题制作涉及到的基本模板及说明整理

wordpress自定义循环列表的php代码

wordpress迁移后图片地址错误问题的解决方法

通过自定义字段重新排序 wordpress 文章方法

wordpress优化头部 去掉版权等信息 wordpress去掉generator

wordpress常用的函数、条件判断以及文件总结

更多相关阅读请进入《wordpress》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...