How? User Menu Custom Links Active Status

Discussion in 'Templates customization' started by crystalmedia, Mar 26, 2020.

  1. crystalmedia

    crystalmedia Member

    Joined:
    Oct 15, 2013
    Messages:
    69
    Menu items keep an active status when clicked on and going to that page, unless they are Custom Links. How can one add custom link menu items to the script (or java script) so that they too keep an active state after being clicked on? In other words they should stay orange in their color (or whatever your site.css color is).

    Menu items like Helpdesk and Payment History MAINTAIN this active style. Custom Menu Items do not.

    ul.am-tabs li.active,
    ul.am-tabs li.normal:hover
    background: url("../img/tab-hover-bg.png")

    Thanks!
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello,

    I am afraid it is a bit tricky in case of custom links but still possible.
    Please put the following code to site.php
    https://www.amember.com/docs/Site.php_file/

    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::USER_MENU, function(Am_Event $e) {

        
    $menu $e->getMenu();
        [
    $config$items] = Am_Navigation_User::getNavigation();

        
    $url parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

        foreach (
    $config as $item) {
            if (
    $item['id'] == 'custom-link' && ($url == $item['config']['uri'] || $_SERVER['REQUEST_URI'] == $item['config']['uri'])) {

                
    $id 'custom-link-' substr(crc32($item['config']['uri']), 08);
                
    $menu->findOneById($id)->setActive(true);
                return;
            }
        }
    });
    crystalmedia likes this.
  3. crystalmedia

    crystalmedia Member

    Joined:
    Oct 15, 2013
    Messages:
    69
    @caesar

    I'm getting an error from the following line of code
    [$config, $items] = Am_Navigation_User::getNavigation();

    Exception ParseError:syntax error, unexpected '=' at line 88 in file /home4/summitt8/public_html/kohera3d/accounts/application/configs/site.php
    Am_App->bootstrap [ bootstrap.php : 20 ]
    require_once [ index.php : 92 ]
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You need to either upgrade PHP to latest version or change it to:
    PHP:
    list($config$items) = Am_Navigation_User::getNavigation();
  5. crystalmedia

    crystalmedia Member

    Joined:
    Oct 15, 2013
    Messages:
    69
    Thank you for the help and effort. Unfortunately it's not working for custom menu items using custom links. I might just have to give up.
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    I am sure it works. I tested it on my local setup.

    Please contact me in helpdesk:
    https://www.amember.com/support
    and refer to this forum thread.

    I will check what is wrong with your installation and fix it.

    Best Regards.

Share This Page