我正在使用FullCalendar從WP上的自定義帖子類型加載事件,通過JSON提要。它正在工作,但需要一些時間來加載。請點擊這裏查看:http://cea3.iscte.pt/en/agenda-3/(六月或八月)。你們中的任何一個人都知道可能導致它的原因嗎?FullCalendar with JSON feed slowloading
這是JSON飼料的完整代碼:
<?php
// - standalone json feed -
header('Content-Type:application/json');
// - grab wp load, wherever it's hiding -
if(file_exists('../../../../wp-load.php')) :
include '../../../../wp-load.php';
else:
include '../../../../../wp-load.php';
endif;
global $wpdb;
// - grab date barrier -
$oneyear = strtotime('-1 year') + (get_option('gmt_offset') * 3600);
// - query -
global $wpdb;
$querystr = "
SELECT *
FROM $wpdb->posts wposts, $wpdb->postmeta metastart, $wpdb->postmeta metaend
WHERE (wposts.ID = metastart.post_id AND wposts.ID = metaend.post_id)
AND (metaend.meta_key = 'tf_events_enddate' AND metaend.meta_value > $oneyear)
AND metastart.meta_key = 'tf_events_enddate'
AND wposts.post_type = 'tf_events'
AND wposts.post_status = 'publish'
ORDER BY metastart.meta_value ASC LIMIT 500
";
$events = $wpdb->get_results($querystr, OBJECT);
$jsonevents = array();
// - loop -
if ($events):
global $post;
foreach ($events as $post):
setup_postdata($post);
// - custom variables -
$custom = get_post_custom(get_the_ID());
$sd = $custom["tf_events_startdate"][0];
$ed = $custom["tf_events_enddate"][0];
// - grab gmt for start -
$gmts = date('Y-m-d H:i:s', $sd);
$gmts = get_gmt_from_date($gmts); // this function requires Y-m-d H:i:s
$gmts = strtotime($gmts);
// - grab gmt for end -
$gmte = date('Y-m-d H:i:s', $ed);
$gmte = get_gmt_from_date($gmte); // this function requires Y-m-d H:i:s
$gmte = strtotime($gmte);
// - set to ISO 8601 date format -
$stime = date('c', $gmts);
$etime = date('c', $gmte);
$thetitle = $post->post_title;
$short_title = substr($thetitle,0,50);
$eventpostid = $post->ID;
$eventslug = wp_get_post_terms($eventpostid, 'tf_eventcategory');
$eventvenueslug = $eventslug[0]->slug;
$tf_events_link = get_post_meta($post->ID, 'tf_events_link', true);
$tf_events_permalink = get_permalink($post->ID);
if ($tf_events_link) { $url_event = $tf_events_link ; }
else { $url_event = $tf_events_permalink; };
// - json items -
$jsonevents[]= array(
'title' => $short_title . '...',
'allDay' => false, // <- true by default with FullCalendar
'start' => $stime,
'end' => $etime,
'url' => $url_event,
'className' => $eventvenueslug
);
endforeach;
else :
endif;
// - fire away -
echo json_encode($jsonevents);
?>
謝謝。
謝謝驗證php。那麼必須是SQL。我有類似的問題運行WP(這是一個大學共享服務器,並沒有辦法測試更好的設置...)。 – AnaRita 2011-05-31 15:38:16
你的加載時間是否相同? 2,3,4秒?我懷疑你會加快它的加載速度。您可以嘗試執行所有localhost並使用某種時間流程程序來查找瓶頸。如果你在六月份舉辦30場比賽會發生什麼?它是非常緩慢還是持續3-4秒? – ppumkin 2011-05-31 15:42:54
它是在2.5和4之間,每月只有一個事件。我會用更多的測試。 – AnaRita 2011-05-31 16:09:22