Magento自定义站点地图

Magento's default sitemap generation produces an XML file that displays all products, including simple products that are associated with configurable products. I only want the configurable product not the associated simple products, can anyone help me?

In Mage/Sitemap/Model/Sitemap.php the function that generates the XML sitemap is generateXml() and the code block that generates the product urls is:

$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></url>',
    htmlspecialchars($baseUrl . $item->getUrl()),
    $date,
    $changefreq,
    $priority
    );
    $io->streamWrite($xml);
}
unset($collection);

I tried using

Mage::getModel('catalog/product')->getCollection();

and changed this line:

htmlspecialchars($baseUrl . $item->getUrl()),

to this line to get it work

htmlspecialchars($item->getProductUrl()),

I get the correct products (without the associated ones), but the urls are like this:

http://www.domain.com/catalog/product/view/id/532/

I want the Url Rewrites, so i changed it to:

$collection = Mage::getModel('catalog/product')->getCollection($storeId)
->addUrlRewrite();

But i still get this:

http://www.domain.com/catalog/product/view/id/532/

Any ideas what's wrong?

you can try with below code.

$product_collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', 16)->addUrlRewrite();
echo $product_collection->getFirstItem()->getProductUrl();

or you can load url separately as you already have product collection than try something like this

Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'attribute_code', Mage::app()->getStore());