Quantcast
Channel: PHP Blog Spot
Viewing all articles
Browse latest Browse all 42

How to generate a sitemap.xml with image in Magento

$
0
0

This is good for SEO if product images include in the sitemap.xml file. We have implemented to add images URL in Magento sitemap.xml file.

file path : app/code/core/Mage/Sitemap/Model/Sitemap.php

Replace this code with existing code.

/**
* Generate products sitemap
*/
$changefreq = (string)Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
$priority = (string)Mage::getStoreConfig('sitemap/product/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
$products = new Varien_Object();
$products->setItems($collection);
Mage::dispatchEvent('sitemap_products_generating_before', array(
'collection' => $products
));
foreach ($products->getItems() as $item) {
$image = Mage::getModel('catalog/product')->load($item->getId())->image;
$img = Mage::getModel('catalog/product')->load($item->getId())->getImageUrl();
$xml = sprintf(
'<url><loc>%s</loc><image:image><image:loc>%s</image:loc></image:image><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
htmlspecialchars($baseUrl . $item->getUrl()),
htmlspecialchars($baseUrl."media/catalog/product" . $image),
$date,
$changefreq,
$priority
);
$io->streamWrite($xml);
}
unset($collection);

The post How to generate a sitemap.xml with image in Magento appeared first on PHP Blog Spot.


Viewing all articles
Browse latest Browse all 42

Trending Articles