I am using php include(mandatory) and simplepie for getting event title and start date, but it keeps giving me 8th august 2013 for every event. I can see the events just fine. Any idea how else to grab the 'when' tag from this? I get error if I use tags. I am not a pro in php and at my wit's end right now!
<?php
if ($_SERVER['QUERY_STRING']) {
parse_str($_SERVER['QUERY_STRING'], $arg);
} else {
$arg['feed'] = '';
$arg['count'] = '';
$arg['more'] = '';
$arg['nodiv'] = '';
}
if (!isset($arg['nodiv'])) $arg['nodiv']='false';
if ($arg['nodiv'] != 'true') {
?>
<div id="news_list">
<?php
}
include('simplepie.inc');
// Let's create a new SimplePie object
$feed = new SimplePie();
$feed = new SimplePie();
$feed->set_file($file);
$feed->enable_cache(false);
$feed->init();
$feed->handle_content_type();
// This is the feed we'll use
$feed->set_feed_url('http://www.google.com/calendar/feeds/aufdccetl%40gmail.com/public/full?max-results=2');
// Let's turn this off because we're just going to re-sort anyways, and there's no reason to waste CPU doing it twice.
$feed->enable_order_by_date(false);
// Initialize the feed so that we can use it.
$feed->init();
// Make sure the content is being served out to the browser properly.
$feed->handle_content_type();
// We'll use this for re-sorting the items based on the new date.
$temp = array();
foreach ($feed->get_items() as $item) {
// We want to grab the Google-namespaced <gd:when> tag.
$when = $item->get_item_tags('http://schemas.google.com/g/2005', 'when');
// Once we grab the tag, let's grab the startTime attribute
$date = $when[0]['attribs']['']['startTime'];
// Let's convert it all to UNIX timestamp. This will be used for sorting.
$sortDate = SimplePie_Misc::parse_date($date);
// Let's format it with date(). This will be the date we display.
$gCalDate = date('l, F j, Y', $sortDate);
// This is how each item will be displayed. We're adding it to the array we created earlier, and indexing it by the $sortDate.
$temp[$sortDate] = '<p> <div class="event_title"><a href=' . $feed->get_permalink(). '>' . $item->get_title() . '</a></div> <div class="event_date"> ' . $gCalDate . '</div> <br/></p>';
}
// Change this to krsort() to display with the furthest event first.
ksort($temp);
// Loop through the (now sorted) array, and display what we wanted.
foreach (array_slice($temp, 0, 3) as $paragraph) {
echo $paragraph;
}
?>
This script fetches the event title and date just fine, It is not getting the public url of the event. Instead shows me a blank calendar. Any ideas on how to get public event info via the url?
To answer your question about limiting events/articles, use the set_item_limit() function. For example:
If you want to limit the total number that displays, use this: