欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

WordPress

當前位置:主頁 > CMS教程 > WordPress >

wordpress自帶的緩存功能使用介紹

來源:本站原創(chuàng)|時間:2020-01-11|欄目:WordPress|點擊: 次

用靜態(tài)化當然可以解決這些問題,不過對于流量不大的博客就沒必要了。 wordpress自帶有緩存體系,關(guān)鍵的函數(shù)你可以在wp-includes/cache.php或 Codex里查找到所有的函數(shù)。


你可以使用下列函數(shù)來實現(xiàn)添加緩存。

復制代碼
代碼如下:

wp_cache_add($key, $data, $flag = '', $expire = 0)

相反的,要刪除緩存數(shù)據(jù)可以通過下面的方法實現(xiàn)。

復制代碼
代碼如下:

wp_cache_delete($id, $flag = '')

提取緩存數(shù)據(jù):

復制代碼
代碼如下:

wp_cache_get($id, $flag = '')

替換緩存數(shù)據(jù):

復制代碼
代碼如下:

wp_cache_replace($key, $data, $flag = '', $expire = 0)

 
舉個例子,如果想輸出最新評論,可以先從緩存里讀取需要輸出的HTML,如果沒有,請求一次,成功后加入緩存,當然時間可以控制。
我知道有很多最新評論,相關(guān)文章免插件輸出的方法,原理都一樣,可以自行改改,貼個我用的:
config.php里面添加

復制代碼
代碼如下:

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('沒有數(shù)據(jù)');
return;
}
//歷遍數(shù)據(jù)
$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" 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獲取自定義字段get

欄    目:WordPress

下一篇:百度官方推出的WordPress結(jié)構(gòu)化數(shù)據(jù)插件百度sitemap

本文標題:wordpress自帶的緩存功能使用介紹

本文地址:http://mengdiqiu.com.cn/a1/WordPress/12769.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有