先说说google站点地图,下面摘抄自网络的内容
Google网站地图(sitemap)是Google提供给网站管理员的一个工具,来提高网站被收录的网页数目。
一般来说,搜索引擎蜘蛛会跟着链接爬行到你网站的所有网页。但很多时候,由于种种原因,并不是所有网页都能被收录进搜索引擎数据库。比如说,你的网站是数据库动态生成的,URL中带有参数,一些网页离主页太远,你的网站PR值太低,新的网页可能过很长时间才有机会被抓取等等。
Google Sitemap就允许站长上传给Google一个网站地图,列出你所有需要被抓取的网页及重要性级别。据很多人证实,Google网站地图确实能提高被Google收录的网页数目,而且似乎Google每天都会抓取sitemap的内容。
简单的说就是让google更快速的更全面的收录你的网站。
magento自带有google站点地图功能,在后台分类->google站点地图我们就能找到。
如果没有的话,我们可以自己添加一个然后生成,很简单。
如果我们需要修改google站点地图,怎么办呢 google站点地图具体参考google的网站
https://support.google.com/news/publisher/topic/2527688?hl=zh-Hans&ref_topic=2481294
下面是自带的格式
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" >
<url>
<loc>http://www.yrtrip.com/default.asp</loc>
<lastmod>2008-07-17</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc> http://www.yrtrip.com/search2.asp?id=32003044&sq=1</loc>
<lastmod>2008-07-17</lastmod>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
</url>
magento的站点地图生成是在SitemapController.php控制器里
/**
* Generate sitemap
*/
public function generateAction()
{
// init and load sitemap model
$id = $this->getRequest()->getParam('sitemap_id');
$sitemap = Mage::getModel('sitemap/sitemap');
/* @var $sitemap Mage_Sitemap_Model_Sitemap */
$sitemap->load($id);
// if sitemap record exists
if ($sitemap->getId()) {
try {
$sitemap->generateXml();
$this->_getSession()->addSuccess(
Mage::helper('sitemap')->__('The sitemap "%s" has been generated.', $sitemap->getSitemapFilename()));
}
catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
catch (Exception $e) {
$this->_getSession()->addException($e,
Mage::helper('sitemap')->__('Unable to generate the sitemap.'));
}
} else {
$this->_getSession()->addError(
Mage::helper('sitemap')->__('Unable to find a sitemap to generate.'));
}
// go to grid
$this->_redirect('*/*/');
}
sitemap模型的generateXml方法里面 sitemap.php
/**
* Generate XML file
*
* @return Mage_Sitemap_Model_Sitemap
*/
public function generateXml()
{
$io = new Varien_Io_File();
$io->setAllowCreateFolders(true);
$io->open(array('path' => $this->getPath()));
if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
}
$io->streamOpen($this->getSitemapFilename());
$io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
$io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">');
$storeId = $this->getStoreId();
$date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
$baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
/**
* Generate categories sitemap
*/
$changefreq = (string)Mage::getStoreConfig('sitemap/category/changefreq', $storeId);
$priority = (string)Mage::getStoreConfig('sitemap/category/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
foreach ($collection as $item) {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
htmlspecialchars($baseUrl . $item->getUrl()),
$date,
$changefreq,
$priority
);
$io->streamWrite($xml);
}
unset($collection);
/**
* Generate products sitemap
*<image:image>
* <image:loc>
* http://www.hotintheshop.com/media/catalog/product/w/b/wb57_pearl-pink.jpg
* </image:loc>
* <image:title>
* 获取产品名称
* </image:title>
*</image:image>
*
*
*
*/
$changefreq = (string)Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
$priority = (string)Mage::getStoreConfig('sitemap/product/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
foreach ($collection as $item) {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority><image:image><image:loc>%s</image:loc><image:title>%s</image:title></image:image></url>',
htmlspecialchars($baseUrl . $item->getUrl()),
$date,
$changefreq,
$priority,
htmlspecialchars($item->getImage()),
htmlspecialchars($item->getName())
);
$io->streamWrite($xml);
}
unset($collection);
/**
* Generate cms pages sitemap
*/
$changefreq = (string)Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
$priority = (string)Mage::getStoreConfig('sitemap/page/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
foreach ($collection as $item) {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
htmlspecialchars($baseUrl . $item->getUrl()),
$date,
$changefreq,
$priority
);
$io->streamWrite($xml);
}
unset($collection);
$io->streamWrite('</urlset>');
$io->streamClose();
$this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
$this->save();
return $this;
}
上面增加了将产品图片写入地图