Magento how to show menus in top menu

Magento how to show menus in top menu

August 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento how to show menus in top menu

Showcasing Menus in Magento: A Comprehensive Guide

Hello developers! I hope this post finds you well. Today, we’re going to dive into a common question for those new to the world of Magento development – how to display top menus with categories and sub-categories effectively.

Understanding the Current Code Structure

Let’s first break down the code provided by our curious beginner:

<?php $_menu = $this->renderCategoriesMenuHtml(0, 'level-top') ?>
<div class="nav-container">
    <ul id="nav">
        <li class="level0 first homelink"><a href="<?php echo $this->getBaseUrl() ?>"><span><?php echo $this->__('Home') ?></span></a></li>
        <?php if($_menu): ?>
            <?php echo $_menu ?>
        <?php endif; ?>
        <?php $additionalLink = themeOptions('additionalLink'); ?>
        <?php $additionalLinkUrl = themeOptions('additionalLinkUrl'); ?>
        <?php if($additionalLinkUrl && $additionalLink): ?>
            <li class="level0 clearence"><a href="<?php echo $additionalLinkUrl ?>" title="<?php echo $additionalLink ?>"><span><?php echo $additionalLink ?></span></a></li>
        <?php endif; ?>
    </ul>
</div>

The code is rendering a simple top menu with a home link and the potential for additional links added via theme options. However, it’s not currently showing any category or sub-category information.

Displaying Category Menus in Magento

To display categories and their sub-categories in your top navigation bar, you’ll want to use Magento’s built-in category rendering functionality more effectively.

Step 1: Understand the renderCategoriesMenuHtml Method

The renderCategoriesMenuHtml method is already being used in the provided code. This method renders a menu block with categories and sub-categories based on the given parameters:

  • The first parameter (0) represents the root category ID.
  • The second parameter (‘level-top’) specifies the type of menu to be rendered.

To display all top-level categories along with their sub-categories, this method is doing exactly what you need. However, the output might not look as expected without proper styling and configuration.

Step 2: Styling Your Menu

The appearance of your Magento menu is primarily controlled by CSS. For a navigation bar that looks similar to the DecoStore demo, you’ll need to apply custom styles to the .nav-container, #nav, and related classes.

You can find these styles in your theme’s CSS files, typically located at app/design/frontend/<package>/<theme>/web/css. The specific file names may vary depending on your theme setup.

Step 3: Configuring Your Menu

To ensure that your categories are displayed correctly, you’ll want to configure your menu settings:

  1. Navigate to the Magento admin panel.
  2. Go to “CMS” > “Pages”.
  3. Select or create the page where you want to display the top menu (e.g., Home).
  4. In the content field for this page, include the PHP code provided above.

Step 4: Testing Your Menu

After making these changes, save your progress and then clear your cache using the following commands in the terminal:

php bin/magento c:f

Then refresh your Magento store’s homepage. You should now see the top menu with categories and their respective sub-categories. The appearance may still require some tweaking to match the DecoStore demo, but this should provide a solid starting point.

Conclusion

Displaying menus in Magento is a fundamental task that every developer encounters. By understanding how to use the renderCategoriesMenuHtml method effectively and configuring your menu settings properly, you can create a top navigation bar with categories and sub-categories that enhances your store’s user experience.

Remember, customizing the appearance of your menu often involves working with CSS files in your theme folder. This allows you to modify colors, fonts, and layouts to match your specific design requirements.

Don’t hesitate to explore Magento’s documentation or reach out to a development expert if you encounter any further challenges. With practice and a solid understanding of the platform, displaying menus will become second nature for your Magento development skills.

Happy coding!

Catalog Themes

Our network