什麼是最有效的方式(按時間)來計算從查詢返回的帖子數量並解析返回的帖子?
第1部分:
我現在有這樣的代碼:
/* $query = {
'numberposts' = '15',
'queryvar1' = '…',
'queryvar2' = '…';
}
*/
$lastposts = get_posts($query); // This uses the original query, and will only return 15 results
$print['returnedcount'] = count($lastposts); // Uses some resources (+ acceptable time)
$query['numberposts'] = "-1"; // Get total results from query
$print['totalposts'] = count(get_posts($query)); // Uses lots of resources (+ lots of time)
我有沒有用這個第二get_posts($query)
- 提供我與其他數據,我怎麼能速度呢?我只需要統計由查詢(返回除了numberposts
- 值帖子總數
第2部分:
-object稍後將用來獲得post數據(ID,日期的$lastposts
,標題,評論數,縮略圖和作者ID)
這些的數據都是inputed到$print
- 陣列是這樣的:
foreach ($lastposts as $post){
// ID
$print['id'][] = (string)$post->ID;
// Date
$print['date'][] = (string)$post->post_date;
// Title
$print['title'][] = (string)$post->post_title;
// Comment count
$print['comments'][] = (string)$post->comment_count;
// Images
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');
$print['image'][] = (string)$image[0];
$imageRetina = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
$print['imageretina'][] = (string)$imageRetina[0];
// Author
$print['author'][] = (string)$post->post_author;
}
有沒有更時間有效的方式來做到這一點?我注意到,圖像操作確實需要一段時間。
非常感謝!
謝謝,我會嘗試(: – Emil 2011-02-24 21:46:03
這是我最終做的。非常感謝!:) – Emil 2011-03-31 16:59:40