Magento 2 : How can I get the sitemap in 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.
Magento 2: By default not providing HTML Sitemap.
Can use Free Extension:
https://www.mageplaza.com/magento-2-seo-extension/
You have following options
- Use Plugin like http://www.mageworx.com/magento-2-sitemap-extension.html
- Create CMS Page & Put Links
- Make Custom Module to Generate HTML Sitemap Programmatically
- Use your Module/CMS Link to access that
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.