How we create the sitemap page in Magento 2 like same we have in Magento 1?
http://example.com/catalog/seo_sitemap/
How we create the sitemap page in Magento 2 like same we have in Magento 1?
http://example.com/catalog/seo_sitemap/
Magento 2: By default not providing HTML Sitemap.
Can use Free Extension:
https://www.mageplaza.com/magento-2-seo-extension/
You have following options
CMS Pages: Can refer Magento 1 Article https://stackoverflow.com/questions/5020257/creating-a-magento-sitemap-page Then Convert it to Magento 2 will gonna Some What Helpfull for CMS Pages
For Categories & Sub Categories: Getting all available category, subcategory list in magento 2
For Categories Product's: Magento 2: get product collection using category id
Magento 2 doesn't have html sitemap url for category and products like in magento 1.xx . For this, you can create a CMS page like 'sitemap/' and call a phtml file
which will include the custom code to call all category
In cms page, call this:
{{block class="Magento\Framework\View\Element\Template" template="Magento_Theme::sitemap.phtml" name="customsitemap"}}
then in phtml, call this:
<?php
$objectManagerr = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $objectManagerr->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
$categoryy = $categoryFactory->create()
->addAttributeToSelect('*');
//->addAttributeToFilter('is_active',1)
//->addAttributeToFilter('is_anchor',1);
$excludedCategory = array(0);
?>
<ul class="sitelist">
<?php foreach ($categoryy as $cc): ?>
<?php if(!in_array($cc->getId(), $excludedCategory)):?>
<div class = "sitemap-list" style="float:left;">
<?php if ($cc->getLevel()==2):?>
<li>
<h3><a href="<?php echo $cc->getUrl(); ?>"><?php echo $cc->getName(); ?></a></h3>
<?php
if($cc->getChildren())
{
$sub = explode(",", $cc->getChildren());
$categoryFactorysub = $objectManagerr->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
$categoryysub = $categoryFactorysub->create()
->addAttributeToSelect('*');
$subcat=$categoryysub->addFieldToFilter('entity_id', array('in' =>$sub));
//$subcat->printlogquery(true);exit;
?>
<ul style="margin-left:15px;">
<?php foreach ($subcat as $subcategories){ ?>
<?php if ($subcategories->getLevel()==3):?>
<div class = "sitemap-list">
<li>
<?php if($subcategories->getImageUrl()): ?>
<div class="mega-menu-ad">
<img src="<?php echo ($subcategories->getImageUrl()); ?>" width="25" height="25" />
</div>
<?php endif; ?>
<a href="<?php echo $subcategories->getUrl(); ?>"><?php echo $subcategories->getName(); ?></a>
<?php
if($subcategories->getChildren())
{
$subSubCat = explode(",", $subcategories->getChildren());
$subsubCatFactory = $objectManagerr->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
$subSubCatCollection = $subsubCatFactory->create()
->addAttributeToSelect('*');
$subSubCollection=$subSubCatCollection->addFieldToFilter('entity_id', array('in' =>$subSubCat));
?>
<ul style="margin-left:20px;">
<?php foreach ($subSubCollection as $subSubcategories){ ?>
<div class = "sitemap-list">
<li>
<?php if($subSubcategories->getImageUrl()): ?>
<div class="mega-menu-ad">
<img src="<?php echo ($subSubcategories->getImageUrl()); ?>" width="25" height="25" />
</div>
<?php endif; ?>
<a href="<?php echo $subSubcategories->getUrl(); ?>"><?php echo $subSubcategories->getName()?></a>
</li>
</div>
<?php } ?>
</ul>
<?php } ?>
</li>
</div>
<?php endif;?>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php endif;?>
</div>
<?php endif;?>
<?php endforeach; ?>
</ul>
This way you can easily create a sitemap URL in the Magento 2.
As of Magento version 2.1.8, the sitemap functionality is included in the admin by default.
Define sitemap location: Marketing > SEO & Search > Site Map. You can also manually generate the sitemap file from here.
Configure cron settings: Stores> Configuration > Catalog > XML Sitemap
Here are instructions for setting up recurring cron jobs. Just like Magento 1.x, the system's cron calls the Magento cron script, which schedules jobs.
You can develop your module which will extend the default Magento module module-sitemap
.
You can based on the Sitemap
model with the \Magento\Sitemap\Model\Sitemap::generateXml
and _initSitemapItems
methods.
2 approaches :
Create a new FO controller
and manage the display with template/layout
etc.
Generate a static file in HTML which will be served by Webserver
to a custom URL.
It will not be very difficult.
Thanks,
Check this plugin it's free and customizable https://marketplace.magento.com/vsourz-html-sitemap.html
You can either use Sitemap extension(https://marketplace.magento.com/fme-advanced-sitemap-generator.html) which will help you to get the job done without programming OR you can simply have a look at this article: https://www.fmeextensions.com/blog/generate-google-optimized-sitemap-xml-in-magento-2/