2013-09-19, 20:55:58
(2013-09-19, 07:35:38)Carlos Wrote: @manubz
Your generate_sitemap function seems to be incomplete. Had you already patched it?
I suggest you do the patch on the original template_functions.php file.
About these patches, I forgot to say that:
- You must have GSDONOTPING disabled (commented out with #, or set to 0 or false) if you want to send the Sitemap to google.
- The Sitemap will not be generated/submitted automatically when you save a post -- you must update some normal page or re-save your GS settings for that.
PS Note that patching the core or plugins is generally not recommended.
Hi,
Exactly, I did not post all the generate_sitemap function, I just had where I add global $xml, $page;
Here is all the generate_sitemap function
Code:
function generate_sitemap() {
if(getDef('GSNOSITEMAP',true)) return;
// Variable settings
global $SITEURL;
global $xml, $page;
$path = GSDATAPAGESPATH;
$count="0";
$filenames = getFiles($path);
if (count($filenames) != 0) {
foreach ($filenames as $file) {
if ( isFile($file, $path, 'xml')) {
$data = getXML($path . $file);
if ($data->url != '404') {
$status = $data->menuStatus;
$pagesArray[$count]['url'] = $data->url;
$pagesArray[$count]['parent'] = $data->parent;
$pagesArray[$count]['date'] = $data->pubDate;
$pagesArray[$count]['private'] = $data->private;
$pagesArray[$count]['menuStatus'] = $data->menuStatus;
$count++;
}
}
}
}
$pagesSorted = subval_sort($pagesArray,'menuStatus');
if (count($pagesSorted) != 0)
{
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>');
$xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'$
$xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
foreach ($pagesSorted as $page)
{
if ($page['private'] != 'Y')
{
// set <loc>
$pageLoc = find_url($page['url'], $page['parent']);
// set <lastmod>
$tmpDate = date("Y-m-d H:i:s", strtotime($page['date']));
$pageLastMod = makeIso8601TimeStamp($tmpDate);
// set <changefreq>
$pageChangeFreq = 'weekly';
// set <priority>
if ($page['menuStatus'] == 'Y') {
$pagePriority = '1.0';
} else {
$pagePriority = '0.5';
}
//add to sitemap
$url_item = $xml->addChild('url');
$url_item->addChild('loc', $pageLoc);
$url_item->addChild('lastmod', $pageLastMod);
$url_item->addChild('changefreq', $pageChangeFreq);
$url_item->addChild('priority', $pagePriority);
exec_action('sitemap-additem');
}
}
//create xml file
$file = GSROOTPATH .'sitemap.xml';
exec_action('save-sitemap');
XMLsave($xml, $file);
}
if (!defined('GSDONOTPING')) {
if (file_exists(GSROOTPATH .'sitemap.xml')){
if( 200 === ($status=pingGoogleSitemaps($SITEURL.'sitemap.xml'))) {
#sitemap successfully created & pinged
return true;
} else {
error_log(i18n_r('SITEMAP_ERRORPING'));
return i18n_r('SITEMAP_ERRORPING');
}
} else {
error_log(i18n_r('SITEMAP_ERROR'));
return i18n_r('SITEMAP_ERROR');
}
} else {
#sitemap successfully created - did not ping
return true;
}
}
Cheers