Events Made Easy Forums How do I … Generate Sitemap

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #53059
    Anonymous
    Inactive

    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";
    
    ?>
    #53060
    Franky
    Keymaster

    I haven’t tested the code yet, but the variable $changefreq is a string, so it should be
    $changefreq=”daily”;

    (With quotes, also for monthly).

    #53063
    Franky
    Keymaster
    #53064
    Anonymous
    Inactive

    Thank you so much Franky!!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘How do I …’ is closed to new topics and replies.
Scroll to Top