Create user sub menu

Hi everyone I need to create a user sub menu based on existing 'Account' elgg native menu.

I use the following code.

if (elgg_is_logged_in()) {

elgg_register_menu_item('topbar', array(

'name' => 'my_sub_menu',

'href' => ''my_pluging/pessek',

'text' => elgg_echo('my_sub_menu:pessek'),

'priority' => 500,

'section' => 'alt',

));

}
 
My menu is displayed on top bar not under "Account" menu.
 
What should I do ?
 
Best regard.
 
  • My menu is displayed on top bar not under "Account" menu.

    Because:

    elgg_register_menu_item('topbar', array(

    Learn this and look at this

  • Thanks

    I have read but still dont know what to do..

    Best regard

  • You need to define the parent name menu item to get it displayed as submenu item. Not sure if it works with the following (I've just looked into start.php of the Aalborg theme plugin where the Accounts menu is defined):

    if (elgg_is_logged_in()) {
        $item = new ElggMenuItem("my_sub_menu", elgg_echo('my_sub_menu:pessek'), 'my_pluging/pessek');
        $item->setParentName('account');
        $item->setPriority(500);
        elgg_register_menu_item('topbar', $item);
    }

    but you can give it a try. Setting the priority is most likely unnecessary. The section is very likely unnecessary. If you want the section set you can add the line

    $item->setSection('alt');

    before  elgg_register_menu_item().

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking