I am working on a Magento 2.1.7 shop and I have created a child-theme of Magento Blank.
In the back-end, I have created a block with a custom, hard-coded, navigation like:
<nav>
<ul>
<li><a href="http://www.examplewebsite.com/">Home</a></li>
<li><a href="http://www.examplewebsite.com/about">About</a></li>
<li><a href="http://www.examplewebsite.com/blog">Blog</a></li>
<li><a href="http://www.examplewebsite.com/contact">Contact Us</a></li>
</ul>
</nav>
By default, Magento displays links to the product categories in the top menu:
<block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600" before="-"/>
How do I, instead, display my custom links block?
-
let me know if any problemManoj Deswal– Manoj Deswal2017年11月01日 12:13:36 +00:00Commented Nov 1, 2017 at 12:13
1 Answer 1
To show your Custom Block Navigation , you simply need to create a widget
Go to
admin > content > widgets > add widgetSelect type as CMS static Block and choose your theme whichever you are using
Fill all the details ( Title / Assign to Store Views / Sort Order to "0"
Add layout update> Display on all pages / Container: After page header
Widget options> Select your block
Keep your cache disabled or clean/flush your cache
You can remove your default navigation by below code in your custom Magento_Theme module, if required.
<referenceBlock name="catalog.topnav" remove="true" />
Magento_Theme\layout\default.xml
I hope this will help you out and others as well
-
I did all the above and the default navigation is displayed as well. Can I alternatively make changes in defaul.xml considering that
<block class="Magento\Framework\View\Element\Template" name="store.menu" group="navigation-sections" template="Magento_Theme::html/container.phtml"> <block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600" before="-" remove="true"/> </block>?Razvan Zamfir– Razvan Zamfir2017年11月01日 12:17:42 +00:00Commented Nov 1, 2017 at 12:17 -
No need to do any coding in XML just simple create widget , see working example here smartparcelbox.com .. navigation and each block on homepage displayed via widget and blocksManoj Deswal– Manoj Deswal2017年11月01日 12:18:48 +00:00Commented Nov 1, 2017 at 12:18
-
first , display your static block on front end using widget ... then we will remove default menu.... flush your cache or check in different browser , if you created widget in above mentioned way then it should displayManoj Deswal– Manoj Deswal2017年11月01日 12:24:10 +00:00Commented Nov 1, 2017 at 12:24
-
magento.stackexchange.com/a/187029/54588 , displayed ?Manoj Deswal– Manoj Deswal2017年11月01日 12:31:49 +00:00Commented Nov 1, 2017 at 12:31
-
I can not use
<referenceBlock name="catalog.topnav" remove="true" />because I need to display the categories on the page still, but in the sidebar. What alternative do I have?Razvan Zamfir– Razvan Zamfir2017年11月01日 13:03:23 +00:00Commented Nov 1, 2017 at 13:03