- This topic has 0 replies, 1 voice, and was last updated 10 years, 1 month ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- The forum ‘Tips’ is closed to new topics and replies.
Events Made Easy › Forums › Tips › Sitemap code example
If you want to create a sitemap, use the following code as an example:
<?php
error_reporting('E_NONE'); // Suppress errors on production server
require('/var/www/html/wordpress/wp-blog-header.php');
$events = eme_get_events(5000, "all", "DESC");
$header = '<?xml version="1.0" encoding="UTF-8"?>'."\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
$urls = "";
$footer = "</urlset>";
if (!empty($events)) {
foreach ($events as $event) {
// Build Sitemap Elements
$locurl = eme_event_url($event);
// Format the date - also in case some EME Events have 0000-00-00 date format, manually add 1st Jan 2012
if(strtotime($event['modif_date']) > strtotime('2010-01-01 00:00')){
$lastmod = date('Y-m-d', strtotime($event['modif_date']));
} else {
$lastmod = date('Y-m-d', strtotime('2010-01-01 00:00'));
}
// Make future events higher priority
if(strtotime($event['event_start_date']) > strtotime('today')){
$priority = 0.9;
$changefreq = "daily";
} else {
$priority = 0.3;
$changefreq = "monthly";
}
// Concatenate List of URLs
$urls .= "<url>\n<loc>$locurl</loc>\n<lastmod>$lastmod</lastmod>\n<changefreq>$changefreq</changefreq>\n<priority>$priority</priority>\n</url>\n";
}
}
// Print Sitemap
$xmlsitemap = $header . $urls . $footer;
// Encode as UTF8 then write to file
$myFile = "/var/www/html/wordpress/sitemap-events.xml";
$fh=fopen($myFile,"w");
fwrite($fh,utf8_encode($xmlsitemap));
fclose($fh);
echo "Sitemap Updated";
?>