Jump to content

bomstudies

New Members
  • Posts

    2
  • Joined

  • Last visited

bomstudies's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for your help! You were absolutely right - I changed these three lines of code as you suggested from the $dir to include the .'/' in the lines of code as follows: // Create a W3C valid date for use in the XML sitemap based on the file modification time if (filemtime( $dir .'/'. $file )==FALSE) { $mod = date( 'c', filectime( $dir .'/' . $file ) ); } else { $mod = date( 'c', filemtime( $dir .'/' . $file ) ); } This updated the sitemap and the dates now read properly. This will be excellent in keeping the sitemap updating automatically and outputting the dates correctly as well. Hope this helps someone out in in the future. BomStudies
  2. I have a simple php script that updates my sitemap automatically. However, when you click the link to the sitemap at www.bomstudies.com/sitemap-xml.php - the last mod date is showing 1969. The php script works for files that are not in sub folders. such as /talks or /commentary. I just need to know what snippet of code i should add, change, or delete to the sitemap php side of it to show the correct last mod date for my xml sitemap. I greatly appreciate your help. Thanks - Here is some of my code: The Config Code: posted as config.php <?php /** * Change the configuration below and rename this file to config.php */ /* * The directory to check. * Make sure the DIR ends ups in the Sitemap Dir URL below, otherwise the links to files will be broken! */ define( 'SITEMAP_DIR', './'); // With trailing slash! define( 'SITEMAP_DIR_URL', 'http://www.bomstudies.com/' ); // Whether or not the script should check recursively. define( 'RECURSIVE', true ); // The file types, you can just add them on, so 'pdf', 'php' would work $filetypes = array( 'php', 'html', 'pdf', 'doc', 'docx', 'xls', 'xlsx' ); // The replace array, this works as file => replacement, so 'index.php' => '', would make the index.php be listed as just / $replace = array( 'index.php' => '' ); // The XSL file used for styling the sitemap output, make sure this path is relative to the root of the site. $xsl = 'xml-sitemap.xsl'; // The Change Frequency for files, should probably not be 'never', unless you know for sure you'll never change them again. $chfreq = 'weekly'; // The Priority Frequency for files. There's no way to differentiate so it might just as well be 1. $prio = 1; // Ignore array, all files in this array will be: ignored! $ignore = array( 'config.php' ); the xml-sitemap.php page <?php /** * XML Sitemap PHP Script * For more info, see: http://yoast.com/xml-sitemap-php-script/ * Copyright ©, 2011 - 2012 - Joost de Valk, joost@yoast.com */ require './config.php'; // Get the keys so we can check quickly $replace_files = array_keys( $replace ); // Sent the correct header so browsers display properly, with or without XSL. header( 'Content-Type: application/xml' ); echo '<?xml version="1.0" encoding="utf-8"?>' . "\n"; $ignore = array_merge( $ignore, array( '.', '..', 'config.php', 'xml-sitemap.php' ) ); if ( isset( $xsl ) && !empty( $xsl ) ) echo '<?xml-stylesheet type="text/xsl" href="' . SITEMAP_DIR_URL . $xsl . '"?>' . "\n"; function parse_dir( $dir, $url ) { global $ignore, $filetypes, $replace, $chfreq, $prio; $handle = opendir( $dir ); while ( false !== ( $file = readdir( $handle ) ) ) { // Check if this file needs to be ignored, if so, skip it. if ( in_array( utf8_encode( $file ), $ignore ) ) continue; if ( is_dir( $file ) ) { if ( defined( 'RECURSIVE' ) && RECURSIVE ) parse_dir( $file, $url . $file . '/' ); } // Check whether the file has on of the extensions allowed for this XML sitemap $fileinfo = pathinfo( $dir . $file ); if ( in_array( $fileinfo['extension'], $filetypes ) ) { // Create a W3C valid date for use in the XML sitemap based on the file modification time if (filemtime( $dir .'/'. $file )==FALSE) { $mod = date( 'c', filectime( $dir . $file ) ); } else { $mod = date( 'c', filemtime( $dir . $file ) ); } // Replace the file with it's replacement from the settings, if needed. if ( in_array( $file, $replace ) ) $file = $replace[$file]; // Start creating the output ?> <url> <loc><?php echo $url . rawurlencode( $file ); ?></loc> <lastmod><?php echo $mod; ?></lastmod> <changefreq><?php echo $chfreq; ?></changefreq> <priority><?php echo $prio; ?></priority> </url><?php } } closedir( $handle ); } ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><?php parse_dir( SITEMAP_DIR, SITEMAP_DIR_URL ); ?> </urlset>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.