0

I am attempting to add a block in place of the subcategory in the main navigation or site navigation. I don't want to use a bloated extension, just minimal code. I am using a blank custom theme I made. In the photo below you will see the "Women" link has a block shown during mouse over dropdown instead of the subcategories. I will code the block with the rest of the mega menu in it per say.

I'm trying to make most of the links on the site navigation this way, 7 for now. The mobile view should be normal subcategory view.

i seen the post sort of like mine. It's not the same.

I GREATLY APPRECIATE the help. if you will please provide details if you can. folder structure / locations and where code gos as i may not be as well versed as the average bear.

enter image description here

2 Answers 2

0

You need to look into this file,

Magento\app\design\frontend\<Your Theme>\<sub folders>\Magento_Theme\templates\html\topmenu.phtml

In my case it is

Magento\app\design\frontend\Solwin\freego\Magento_Theme\templates\html\topmenu.phtml

Look for variable $_menu

The sub categories will be retrived from this code block

<?php $_menu = $block->getHtml('level-top', 'submenu', $columnsLimit) ?>

If you want to override you can change the below HTML.

<nav class="navigation" role="navigation">
    <ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
        <?php if ($showhomelink) { ?>
            <li class="level0 level-top <?php if ($ishome) { ?> active <?php } ?>">
                <a class="level-top" href="<?php echo $baseUrl; ?>">
                    Home
                </a>
            </li>
        <?php } ?>
        <?php /* @escapeNotVerified */ echo $_menu; ?>
    </ul>
</nav>
0
0

You can get this by plugin after method

app/code/Vendor/Module/etc/di.xml Now create app/code/Vendor/Module/Plugin/CategoryCustomItemPlugin.php

namespace Vendor\Module\Plugin;

class CategoryCustomItemPlugin
{

public function afterGetHtml(\Magento\Theme\Block\Html\Topmenu $topmenu, $html)
{
$customurl= $topmenu->getUrl('yoururl'); //here you can set link
$CurrentUrl = $topmenu->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
if (strpos($CurrentUrl,'yoururl') !== false) {
$html .= "
";
} else {
$html .= "
";
}
$html .= "" . __("yoururl") . "";
$html .= "
";
return $html;
}
}

This way you can add your static-block code as an HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.