用动态化当然能够处理这些成绩,不过关于流量不大的博客就没必要了。 wordpress自带有缓存体系,要害的函数你能够在wp-includes/cache.php或 Codex里查找到一切的函数。
你能够应用下列函数来完成增加缓存。
wp_cache_add($key, $data, $flag = '', $expire = 0)
wp_cache_delete($id, $flag = '')
wp_cache_get($id, $flag = '')
wp_cache_replace($key, $data, $flag = '', $expire = 0)
define('WP_CACHE', true);
<?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><p class=\'recentcommentslink_excerpt\'>' . get_avatar($rcm->comment_author_email, 64). $s_excerpt . '</p>';</p>
<p>   $output .=  '<li><p id="C_' . $rcm->comment_ID . '_d" style="display:none">' . $contents . '</p>' . '<a id="C_' . $rcm->comment_ID . '" class="recentcommentslink" href="' . get_permalink($rcm->comment_post_ID) . '#comment-' . $rcm->comment_ID . '" >' . get_avatar($rcm->comment_author_email, 32) . '</a></li>';</p>
<p> }
 //输入后退出缓存
 wp_cache_add('recentComments_'.$cacheID,$output, 'Deamwork');
 echo $output;
}
最初,试试成果吧~
以上就是安达网络工作室关于《wordpress自带的缓存功能使用介绍》的一些看法。更多内容请查看本栏目更多内容!
增加 Ctrl+Enter 快捷回复 这里送上两种办法,首先是 jQuery 办法,前段工夫不断在钻研 jQuery ,因而对 jQ...
本文实例讲述了WordPress应用自定义文章类型完成恣意模板的办法。分享给大家供大家参考,详细如下: 这几天...
自带的导航菜单性能是 WordPress 3.0+ 中惟一执得让人眼睛一亮的性能了,在新做主题的进程中再一次让我眼睛...
插件称号:多备份 插件下载:http://www.dbfen.com/tools/dbfen_wordpress_20141112.zip 第1步下载紧缩包后...
复制代码代码如下:add_filter( 'wp_handle_upload_prefilter', 'custom_upload_name' ); function custom...
本文实例讲述了WordPress完成回复文章评论后发送邮件告诉的性能。分享给大家供大家参考,详细如下: 很多时...