Hello everyone,
I'm building a menu for a page in the sidebar.
$ items = ....
elgg_register_menu_item ('page', $ items);
At the end of the menu is displayed in alphabetical order, but I want it in the order that I have registered.
Does anyone know where to change this?
In ElggmenuBuilder class documentation, I can see a function
00184 protected function sort($sort_by) { 00185 00186 // sort sections 00187 ksort($this->menu); 00188 00189 switch ($sort_by) { 00190 case 'text': 00191 $sort_callback = array('ElggMenuBuilder', 'compareByText'); 00192 break; 00193 case 'name': 00194 $sort_callback = array('ElggMenuBuilder', 'compareByName'); 00195 break; 00196 case 'priority': 00197 $sort_callback = array('ElggMenuBuilder', 'compareByWeight'); 00198 break; 00199 case 'register': 00200 // use registration order - usort breaks this 00201 return; 00202 break; 00203 default: 00204 if (is_callable($sort_by)) { 00205 $sort_callback = $sort_by; 00206 } else { 00207 return; 00208 } 00209 break; 00210 }
But do not know how to use this.
Can anyone tell me a cool link?
I've been looking everywhere and have not found anything.
Thanks in advance.
Frank.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Juho Jaakkola@juho.jaakkola

Juho Jaakkola - 0 likes
- Juho Jaakkola@juho.jaakkola

Juho Jaakkola - 0 likes
- Frank García@garlofrank

Frank García - 0 likes
You must log in to post replies.If you're printing the menu yourself, you can define the order by passing in the "sort_by" parameter:
If you're modifying an existing menu, you can use the 'prepare', 'menu:<menu name>' hook to modify the menu items before they are printed.
First register the plugin hook handler like this: https://github.com/Elgg/Elgg/blob/1.8/engine/lib/admin.php#L305
And then implement your own sorting function like has been done here: https://github.com/Elgg/Elgg/blob/1.8/engine/lib/admin.php#L384
(I changed the topic title to be more decriptive.)
Hi Juho,,,
Thanks for your quick response.
This works!!!, but I changed this option in sidebar.php (added to my plugin).