No edit summary |
No edit summary |
||
Line 44: | Line 44: | ||
** If this is the last sub-item in the sub-menu, then the line <code>'is_last'=true;</code> should be added/defined in order for the CSS to properly close the dropdown list. | ** If this is the last sub-item in the sub-menu, then the line <code>'is_last'=true;</code> should be added/defined in order for the CSS to properly close the dropdown list. | ||
Lastly, for correct coding, each of of the sub-arrays which was opened, must be closed. i.e. for each (, there must also be a ) | Lastly, for correct coding, each of of the sub-arrays which was opened, must be closed. i.e. for each (, there must also be a ) | ||
*If the title of the new menu item starts with $txt[' this is called a text string. all the text strings in smf are found in the Themes/default/languages folder. text strings for the main menu are usually found in the index.<your language>.php file. If a new menu item is added and a text string is used the string must be defined in the index.<your language>.php file. | |||
===See also=== | ===See also=== |
Revision as of 13:58, 18 June 2013
The following instructions will describe how to add a link in the main menu. As described, the instructions will add a menu item just before the members list in the main menu. To place the menu item in a different order, find the appropriately names section of the array and add the following code before it.
In /Sources/Subs.php
find:
'mlist' => array(
add before:
'menu_action' => array( 'title' => 'text for menu', 'href' => $scripturl, 'show' => true, 'sub_buttons' => array( 'sub_menu_action' => array( 'title' => 'text for sub-menu', 'href' => $scripturl . '?action=newaction', 'show' => true, 'is_last'=> true, ), ), ),
As you can see, each entry in the array has a main section and a sub_button(s) section. Each of the items in the main level of the array must be present and defined.
- The 'menu_action' is a standard php variable name (no spaces, etc) that clearly (and concisely) describes the action.
- The title is the text that will be shown in the main menu. If the forum uses only a single language, this can be defined directly in the code (hardcoded). However, if this is being coded for a mod, or the forum uses more than one language, the text for this item should use a $txt string variable which is then defined in the modifications.each_language.php file(s).
- The href is the link that the menu item will link to. This can be a relative url, an absolute url, or, as in this case, a url defined by the standard $scripturl global variable.
- The show variable defines whether this menu item is displayed or not. This can be set to true, false, or defined to use some sort of logic (i.e. allowedTo('admin_forum'))
- If there are no further drop-down/sub-level buttons for this menu item, then sub_buttons can be defined as and empty sub-array. i.e.
'sub_buttons' => array( ),
- However, if the menu item is going to have sub-menu items, then each sub-menu action needs to be defined under sub_buttons.
- The 'sub_menu_action' is a standard php variable name (no spaces, etc) that clearly (and concisely) describes the sub-action.
- The title is the text that will be shown in the sub-menu. Like the main menu tile-text, if the forum uses only a single language, this can be defined directly in the code (hardcoded). However, if this is being coded for a mod, or the forum uses more than one language, the text for this item should use a $txt string variable which is then defined in the modifications.each_language.php file(s).
- The href is the link that the sub-menu item will link to. Again, this can be a relative url, an absolute url, or, as in this case, a url defined by the standard $scripturl global variable along with an action (which must exist in the index.php action array).
- The show variable defines whether this sub-menu item is displayed or not. This can be set to true, false, or defined to use some sort of logic (i.e. allowedTo('admin_forum'))
- If this is the last sub-item in the sub-menu, then the line
'is_last'=true;
should be added/defined in order for the CSS to properly close the dropdown list.
Lastly, for correct coding, each of of the sub-arrays which was opened, must be closed. i.e. for each (, there must also be a )
- If the title of the new menu item starts with $txt[' this is called a text string. all the text strings in smf are found in the Themes/default/languages folder. text strings for the main menu are usually found in the index.<your language>.php file. If a new menu item is added and a text string is used the string must be defined in the index.<your language>.php file.