Jump to content

How to add submenu into primary navbar main menu


Recommended Posts

Hi,

 

I added Main Menu into primary navbar as a server and trying to add sub menu as Dedicated Server & Cloud Server.


 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)

{

$primaryNavbar->addChild('Dedicated Server')

->setUri('https://fratechnology.com/billing/cart.php?gid=1')

->setOrder(11);



$primaryNavbar->addChild('Cloud Server')

->setUri('https://fratechnology.com/billing/cart.php?gid=3')

->setOrder(12);

});

Regards,

Md Fazla Rabby

FRA Technology

Edited by WHMCS ChrisD
Moved code into a code box
Link to comment
Share on other sites

if you want to create a 'Servers' item on the navbar, with other links beneath it in a sub-menu, you would need to do this..

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
   {

   $primaryNavbar->addChild('Servers')
               ->setOrder(11);

   $primaryNavbar->getChild('Servers')
               ->addChild('Dedicated Server')
               ->setUri('https://fratechnology.com/billing/cart.php?gid=1')
               ->setOrder(1);

   $primaryNavbar->getChild('Servers')            
               ->addChild('Cloud Server')
               ->setUri('https://fratechnology.com/billing/cart.php?gid=3')
               ->setOrder(2);
});

Link to comment
Share on other sites

Hi,

 

Lots of thank you. Its working !!!! I want to remove some old menu from the list.

Example: that menu has (Network status) how do i hide or remove from the menu list also i want to change the color of menu row.

What will be the code ?

 

Regards,

Md Fazla Rabby

FRA Technology LLC

Link to comment
Share on other sites

Lots of thank you. Its working !!!! I want to remove some old menu from the list.

Example: that menu has (Network status) how do i hide or remove from the menu list also i want to change the color of menu row.

What will be the code ?

if you want to remove Network Status when the client is not logged in, you would use...

 

http://forum.whmcs.com/showthread.php?112699-Small-problem-with-hooks!&p=457602#post457602

 

note that it removes more than just the Network Status menuitem, so you would need to edit it depending on what you want to remove...

 

alternatively if you just want to remove 'Network Status', then you could use the hook below...

 

http://forum.whmcs.com/showthread.php?108806-Remove-Menu-Items-v6&p=445599#post445599

 

if they are logged in, you could use the code in the thread below...

 

http://forum.whmcs.com/showthread.php?113019-how-to-remove-the-two-items-on-v6&p=458910#post458910

 

with regards to menu color, that's not changed by a hook but an edit to the .css

 

http://forum.whmcs.com/showthread.php?103630-Changing-teal-navbar-color&p=428063#post428063

 

if you make your change in a custom.css file, then you won't need to update it each time you upgrade WHMCS.

 

http://docs.whmcs.com/Customising_the_Six_Theme#Applying_Custom_CSS_Styling

Link to comment
Share on other sites

  • 5 months later...

I have a question.

If i need more sub level? I need only one sub level more to move items to right side.

 

Example:

Servers

*Dedicated Server

*That level i need

*Cloud Server

 

I tried that code, but result is "nothing".

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
   {

   $primaryNavbar->addChild('Servers')
               ->setOrder(11);

   $primaryNavbar->getChild('Servers')
               ->addChild('Dedicated Server')
               ->setUri('https://fratechnology.com/billing/cart.php?gid=1')
               ->setOrder(1);

   $primaryNavbar->getChild('Servers')
	->getChild('Dedicated Server')
               ->addChild('Test1')
               ->setUri('http://random.url')
               ->setOrder(1)
	->setlabel (Lang::trans('menu2design'));

   $primaryNavbar->getChild('Servers')            
               ->addChild('Cloud Server')
               ->setUri('https://fratechnology.com/billing/cart.php?gid=3')
               ->setOrder(2);
});

 

Thank you for any advice :idea:

Link to comment
Share on other sites

out of the box, I don't think you can do that... I believe that the theme is currently only coded for parent and child menus, not grandchildren...

I suppose potentially you could try to modify navbar.tpl to see if you could get it to use grandchildren - but that's not for me on a Sunday! :)

 

the alternate way would be to fake indentation - with the optional use of an icon...

 

Y1TlGY2.pngLGwp6VX.png

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
   {

   $primaryNavbar->addChild('Servers')
                   ->setOrder(11);

   $primaryNavbar->getChild('Servers')
                   ->addChild('Dedicated Server')
                   ->setUri('https://fratechnology.com/billing/cart.php?gid=1')
                   ->setOrder(1);

   $primaryNavbar->getChild('Servers')
                   ->addChild('Test1')
                   ->setUri('http://random.url')
                   ->setOrder(2)
                   ->setIcon('fa-caret-right')
                   ->setlabel('   Test1');

   $primaryNavbar->getChild('Servers')            
                   ->addChild('Cloud Server')
                   ->setUri('https://fratechnology.com/billing/cart.php?gid=3')
                   ->setOrder(10);
}); 

I know it's not exactly what you're wanting to do, but it's going to be the simplest solution - short of rewriting the template/css code! :)

 

btw - if you want some reading on a semi-related matter, you can just add a sidebar to a navbar in the template code... :idea:

 

https://forum.whmcs.com/showthread.php?116654-Remove-Sidebar-from-product-detail-page&p=471806#post471806

 

but it's probably not applicable for your situation as I assume what you're really trying to do is add the Product Categories under "Servers" as children in the navbar, and then include the products in each category as grandchildren.... in fact, you could probably code a hook to automatically write the indented product links for you, but that may not be necessary unless you were constantly changing products.

Link to comment
Share on other sites

  • 2 months later...

This is exactly what I need. I guess it would be just modifiy the navbar.tpl - I´ll tried a very easy dirty hack to solve this problem - with this navbar.tpl modification the code above for a submenu level works for me very fine :)

 

{foreach $navbar as $item}

<li menuItemName="{$item->getName()}"{if $item->hasChildren()} class="dropdown"{elseif $item->getClass()} class="{$item->getClass()}"{/if} id="{$item->getId()}">

<a {if $item->hasChildren()}class="dropdown-toggle" data-toggle="dropdown" href="#"{else}href="{$item->getUri()}"{/if}{if $item->getAttribute('target')} target="{$item->getAttribute('target')}"{/if}>

{if $item->hasIcon()}<i class="{$item->getIcon()}"></i> {/if}

{$item->getLabel()}

{if $item->hasBadge()} <span class="badge">{$item->getBadge()}</span>{/if}

{if $item->hasChildren()} <b class="caret"></b>{/if}

</a>

{if $item->hasChildren()}

<ul class="dropdown">

{foreach $item->getChildren() as $item}

<li menuItemName="{$item->getName()}"{if $item->hasChildren()} {elseif $item->getClass()} class="{$item->getClass()}"{/if} id="{$item->getId()}">

<a {if $item->hasChildren()} href="#"{else}href="{$item->getUri()}"{/if}{if $item->getAttribute('target')} target="{$item->getAttribute('target')}"{/if}>

{if $item->hasIcon()}<i class="{$item->getIcon()}"></i> {/if}

{$item->getLabel()}

{if $item->hasBadge()} <span class="badge">{$item->getBadge()}</span>{/if}

 

</a>

{if $item->hasChildren()}

<ul class="dropdown">

{foreach $item->getChildren() as $childItem}

<li menuItemName="{$childItem->getName()}"{if $childItem->getClass()} class="{$childItem->getClass()}"{/if} id="{$childItem->getId()}">

<a href="{$childItem->getUri()}"{if $childItem->getAttribute('target')} target="{$childItem->getAttribute('target')}"{/if}>

{if $childItem->hasIcon()}<i class="{$childItem->getIcon()}"></i> {/if}

{$childItem->getLabel()}

{if $childItem->hasBadge()} <span class="badge">{$childItem->getBadge()}</span>{/if}

</a>

</li>

{/foreach}

</ul>

{/if}

</li>

{/foreach}

</ul>

{/if}

</li>

{/foreach}

Link to comment
Share on other sites

  • 1 year later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated