Search the Community
Showing results for tags 'sitemap'.
-
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>
-
I was trying to write a class which would generate a sitemap for every post which is made or edited, but i don't seem to understand what is my mistake here. class sitemap { var $file_net; var $url_net; var $extention_net; var $freq_net; var $priority_net; function set() { $file = $this->file_net; $url = $this->url_net; $extention = $this->extention_net; $freq = $this->freq_net; $priority = $this->priority_net; } function Path ($p) { $a = explode ("/", $p); $len = strlen ($a[count ($a) - 1]); return (substr ($p, 0, strlen ($p) - $len)); } function GetUrl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); return $data; } function Scan($url) { global $scanned, $pf, $extension, $skip, $freq, $priority; echo "scan url $url\n"; array_push ($scanned, $url); $html = GetUrl ($url); $a1 = explode ("<a", $html); foreach ($a1 as $key => $val) { $parts = explode (">", $val); $a = $parts[0]; $aparts = explode ("href=", $a); $hrefparts = explode (" ", $aparts[1]); $hrefparts2 = explode ("#", $hrefparts[0]); $href = str_replace ("\"", "", $hrefparts2[0]); if ((substr ($href, 0, 7) != "http://") && (substr ($href, 0, != "https://") && (substr ($href, 0, 6) != "ftp://")) { if ($href[0] == '/') $href = "$scanned[0]$href"; else $href = Path ($url) . $href; } if (substr ($href, 0, strlen ($scanned[0])) == $scanned[0]) { $ignore = false; if (isset ($skip)) foreach ($skip as $k => $v) if (substr ($href, 0, strlen ($v)) == $v) $ignore = true; if ((!$ignore) && (!in_array ($href, $scanned)) && (strpos ($href, $extension) > 0) ) { fwrite ($pf, "<url>\n <loc>$href</loc>\n" . " <changefreq>$freq</changefreq>\n" . " <priority>$priority</priority>\n</url>\n"); echo $href. "\n"; Scan ($href); } } } } $pf = fopen ($file, "w"); if (!$pf) { echo "cannot create $file\n"; return; } fwrite ($pf,"<?xml version=\"1.0\" encoding=\"UTF-8\"?> <urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"> <!-- created with SiteMap Generator --> <url> <loc>$url/</loc> <changefreq>daily</changefreq> </url> "); $scanned = array(); Scan ($url); fwrite ($pf, "</urlset>\n"); fclose ($pf); }
-
I am creating a dynamic human readable sitemap from mysql>php. the array is created with; (array structure can be altered if this is causing the grief) <?php $row['category'] = varchar; // list of 10 categories $row['status'] = int; // 0,1 or 2 $row['id'] = int; // 1,2,3,4... (AI) // set the title for link $this->sitemap[$row['category']][$row['status']]['title'][$row['id']] = $row['seo_title']; // set the url for link $this->sitemap[$row['category']][$row['status']]['url'][$row['id']] = $row['slug'].".php"; ?> My required output to be as; <ul> <li>category[0] <ul> // all category[0][2] <li><a href="category[0][2]['title']['the row id']">category[0][2]['title']['the row id']</a></li> etc... // all category[0][1] <ul> <li><a href="category[0][1]['title']['the row id']">category[0][1]['title']['the row id']</a></li> etc.... // all category[0][0] <ul> <li><a href="category[0][0]['title']['the row id']">category[0][0]['title']['the row id']</a></li> </ul> </ul> <li>category[1] <ul> // all category[1][2] <li><a href="category[1][2]['title']['the row id']">category[1][2]['title']['the row id']</a></li> etc... keep in mind where caetgory[0] is a string as key, not an integer. Any ideas or questions welcomed, thanks.
-
Hi guys, I'm trying to write a php page that will function as an xml sitemap. I'm getting the following error, however: This page contains the following errors: error on line 1 at column 94: Extra content at the end of the document My code is below. Any ideas? <?php header("Content-Type: text/xml;charset=iso-8859-1"); echo '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'; include 'includes/db_connect.php'; $sitemap = generateSitemap(); foreach ($sitemap as $key => $value) { ?> <url> <loc>http://failauthority.com/<?php echo $value['id']; ?></loc> <lastmod><?php echo date("Y-m-d"); ?></lastmod> <changefreq>weekly</changefreq> <priority>.5</priority> </url> <?php } ?> </urlset>