PHP code example of monsieurbiz / mbiz_sitemap

1. Go to this page and download the library: Download monsieurbiz/mbiz_sitemap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

monsieurbiz / mbiz_sitemap example snippets


class Acme_Demo_Model_Observer
{
    public function generateSitemaps(Varien_Event_Observer $observer)
    {
        // Fill the sitemap
        $sitemap = Mage::getModel('mbiz_sitemap/sitemap');
        $collection = Mage::getResourceModel('acme_demo/article_collection');
        foreach ($collection as $article) {
            $sitemap->addUrl(
                $article->getUrl(), // URL
                date('c', strtotime($article->getUpdatedAt())), // Last Updated
                'monthly', // Frequency
                0.8 // Priority
            );
        }
      
        // Generate the XML file
        $sitemap->generate(
            Mage::getBaseDir() . DS . 'sitemaps' . DS . 'articles.xml', // The XML file
          	Mage::getUrl('', [ // The URL
            	'_direct' => 'sitemaps/articles.xml',
            	'_type' => Mage_Core_Model_Store::URL_TYPE_DIRECT_LINK,
        	])
        );
        $observer->getIndex()->addSitemap($sitemap);
    }
}

Mage::getSingleton('mbiz_sitemap/cron')->generateSitemaps();