Jump to content

Add Sidebar on Affiliates Page


D9Hosting

Recommended Posts

I'm working on a new WHMCS theme based on Six and have been having a bit of fun in getting the navigation and sidebars to work how we want. I've been able to create hooks to add and remove items from existing nav bars and sidebars but have become stuck on creating a brand new sidebar to display on our Affiliate pages.

 

We use the default affiliates.php page, but also have custom pages to display promo banners, email swipes, discount coupons, etc. So wondered if any coding guru's reading this could point me in the right direction for generating a new sidebar item and then to have it display on certain pages. (affiliates.php and our custom pages)

 

Thanks!

Link to comment
Share on other sites

as a basic example, to add a new sidebar to only the affiliates page, you could do something like this...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
   if (APP::getCurrentFileName()=="affiliates"){

       $secondarySidebar->addChild('sidebar1', array(
               'label' => 'My New Sidebar',
               'order' => '10',
               'icon' => 'fa-money'
       ));
       $secondarySidebar->getChild('sidebar1')
               ->addChild('child1', array(
               'label' => 'Brian',
               'uri' => 'http://www.google.com'
       ));        

   }
});

0ja9gGt.png

 

to use on multiple pages, you can just expand that opening IF statement to use all the pages where you want this sidebar to appear.... if you need to use templatefile to specify a template rather than a page, the thread below might help.

 

https://forum.whmcs.com/showthread.php?125626-How-to-get-templatefile-in-a-hook-and-use-client-Custom-Fields-in-a-SideBar

 

and remember that sidebar children can't have the same name, so you can call them 'child1', 'child2' etc or whatever you want - as long as the names are unique. :idea:

Link to comment
Share on other sites

Thanks Brian,

That pointed me in the right direction and I've hacked the following together that seems to be working well if anyone else runs into the same issue:

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
  $currentFile = APP::getCurrentFileName();

switch ($currentFile) {
 case 'custompage1':
 case 'custompage2':
 case 'custompage3':

   $secondarySidebar->addChild('sidebar1', array(
               'label' => 'My New Sidebar',
               'order' => '10',
               'icon' => 'fa-money'
       ));
       $secondarySidebar->getChild('sidebar1')
               ->addChild('child1', array(
               'label' => 'Brian',
               'uri' => 'http://www.google.com'
       ));        

   break;
}
});

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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