如何在OpenCart 3.0.2.0主菜单中添加自定义链接
Hey there! Let's walk through how to add custom links to your OpenCart 3.0.2.0 main menu—super straightforward once you know the steps. I'll cover both the no-code backend method (perfect for default themes) and a code tweak if you're using a custom theme that overrides the default menu system.
This is the easiest way if you're using OpenCart's default theme or a theme that respects the admin menu settings:
- Log into your OpenCart admin panel, then navigate to Design > Menus from the left sidebar.
- You’ll see your existing main menu (usually labeled "Main Menu"). Click the Edit button next to it.
- In the menu editor, hit the Add Menu button at the top right to create a new menu item.
- Fill out the key fields:
- Menu Name: The text that will show up in your main menu (e.g., "Our Story", "Return Policy").
- Route: For internal pages, use OpenCart's route syntax (you can find this by opening the target page in admin and checking the URL—like
information/information&information_id=4for the default About Us page). For external links, just paste the full URL (e.g.,https://your-brand-blog.com). - Status: Set to Enabled to make the link visible.
- Sort Order: Adjust this number to position your link (lower numbers appear earlier in the menu).
- Save your changes, then clear your store's cache (go to System > Maintenance > Cache and click "Clear").
- Head to your store frontend—your new custom link should be live in the main menu!
If the backend method doesn't work, it's likely your theme has a custom menu template. Here's how to add links directly:
- Access your store files via FTP or cPanel File Manager. Go to
catalog/view/theme/[your-theme-folder]/template/common/. - Open
header.tpl(or sometimesmenu.tpl, depending on your theme) in a plain text editor. - Find the loop that renders category menu items—it’ll look something like this:
<?php foreach ($categories as $category) { ?> <!-- Existing category menu HTML here --> <?php } ?> - Insert your custom link right after (or before) this loop, matching the existing menu's HTML structure. For a simple top-level link:
If you want a dropdown submenu, mirror the dropdown structure from the existing category items in the file.<li class="dropdown"> <a href="https://your-custom-link.com" class="dropdown-toggle">Your Custom Link Text</a> </li> - Save the file, clear your store cache, and refresh your frontend—your new link should appear.
Pro Tip: Always back up your files before making code edits, and test changes on a staging site first if possible to avoid breaking your live store!
内容的提问来源于stack exchange,提问作者Akshay Vasu

