Events Made Easy › Forums › How do I … › Generate Sitemap
Tagged: sitemap
- This topic has 3 replies, 2 voices, and was last updated 10 years, 2 months ago by Anonymous.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
Sat 18 Oct 2014 at 18:32 #53059AnonymousInactive
Hi,
After reading this post, i try to put sitemap-events.php on my WP directory (ritc) but i can’t generate sitemap-events.xml. Can you help me, please?Here is the code:
<?php error_reporting('E_ALL'); // Suppress errors on production server require('/var/www/vhosts/romaintheclub.com/httpdocs/ritc/wp-blog-header.php'); global $wpdb; //$sql = "SELECT * FROM " . $wpdb->prefix . "eme_events ORDER BY <code>rc_eme_events</code>.<code>event_start_date</code> DESC"; $sql = "SELECT * FROM " . $wpdb->prefix . "eme_events ORDER BY <code>rc_eme_events</code>.<code>event_id</code> DESC LIMIT 5000"; // Show 5000 most recently added to prevent server timeout $events = $wpdb->get_results($sql); // Run our query, getting results as an object if (!empty($events)) { // If the query returned something $header = "<?xml version="1.0" encoding="UTF-8"?>n" . "<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">n"; $urls = ""; $footer = "</urlset>"; foreach ($events as $event) { // Loop though our results! // Build Sitemap Elements $locurl = "http://www.romaintheclub.com/events/$event->event_id/$event->event_slug"; // 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> <priority>$priority</priority>n </url>n"; } // Print Sitemap $xmlsitemap = $header . $urls . $footer; } // Encode as UTF8 then Write to file $myFile = "//var/www/vhosts/romaintheclub.com/httpdocs/sitemap-events.xml"; $fh=fopen($myFile,"w"); fwrite($fh,utf8_encode($xmlsitemap)); fclose($fh); echo "Sitemap Updated"; ?>
Sat 18 Oct 2014 at 18:41 #53060FrankyKeymasterI haven’t tested the code yet, but the variable $changefreq is a string, so it should be
$changefreq=”daily”;(With quotes, also for monthly).
Sun 19 Oct 2014 at 23:41 #53063FrankyKeymasterI created a code example here:
http://www.e-dynamics.be/wordpress/?topic=sitemap-code-example
Mon 20 Oct 2014 at 08:16 #53064AnonymousInactiveThank you so much Franky!!
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘How do I …’ is closed to new topics and replies.