I couldn't locate the discussion pages for drupal 6 menu features. Could someone point me there? I'm very interested to find out if anyone else feels there should be the ability to specify a different sort order for menu items. Right now items are sorted first by weight and then by name, but sometimes it would be more appropriate to specify that menu items within a specific branch should use their publish date for sorting.

Comments

jou00jou’s picture

http://drupal.org/node/102338

I agree and I feel that an embedded drop down menu is needed as well.

sepeck’s picture

This is the way the sort order has always worked.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

ardarvin’s picture

I'm assuming this would count as a "feature" and since all features are frozen for 6.0, maybe we could hope for Drupal 7 to have this seemingly obvious option?

Not being able to sort by submission date is one of my biggest pet peeves.

sepeck’s picture

Well, it would be a feature request against Drupal 7.

I am not sure how having items added to the menu sort by date is an obvious feature, in four years and and six releases I've been here, this is the first time I've seen it requested. That's all right though, everyone's needs are a bit different.

It also may be that I am reading something completely different then you are asking.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

ardarvin’s picture

Nope, you read it correctly. I guess it seems obvious to me because I'm completely new to Drupal. Those who've been around longer probably start thinking rather "Drupalish" (whatever that means).

Odd nobody has requested this before, since it is how Drupal seems to organize it's data: new nodes float to the top. For instance, returning a taxonomy will put newest nodes first. Having that option for a menu system would seem to make sense.

Perhaps people just do a work around by using "weight", but when you are trying to organize 50+ articles, that breaks down.
Or perhaps I'm a nut, and nobody wants to organize their menus this way.

sepeck’s picture

If you check out the downloads page, hit f3 in your browser and go with the word menu, you'll find any number of specialty solutions that may get you started for now.

The Drupal menu system isn't really an automatic thing, nor for the most part was it designed to be. It's designed to build links on. For anything more specialized we've always relied on contrib modules. With Drupal 6, the menu system has been rebuilt fro the group up in many ways so it may be a while before the specialty solutions make their way into contrib modules for D6. For more on the new menu system in Drupal 6 see here

Adding the feature request certainly won't hurt and may spark some ideas.

Another idea... Use Views module to create a view sorted by date, make a block for that view and use that auto generated block for the menu. That's a way that I can think of off the top of my head. Downside is that views doesn't do well if you need your menu to have a hierarchy.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

StephenN’s picture

I had a similar issue where, for one specific area of the site I wanted that subsection of the nav sorted by creation date. Unable to find any hook or preprocessor function that would allow me to alter the menu tree I've gone for a direct database manipulation by placing the following inside hook_nodeapi. This will only work if all items you want to rearrange are at the same level and you will need to alter the subselect for whichever link path you wish to act as parent.

 switch ($op) {
	    case 'insert':
	    case 'update':
		 if($node->type='news') {
		 	//db hack to force news submenu to be ordered by descending creation date
	     	//SQL statement uses subselect to return the mlid for the top level we are interested in, we then join on the node table by selecting nid as the portion of link_path after the "/" n.b assumes path format of node/nid 
	        $sql .= "SELECT distinct ml.mlid, ml.link_title, n.created from menu_links ml, node n WHERE plid=(select mlid from menu_links where link_path='news' and menu_name='primary-links') AND status=1 AND SUBSTR(link_path,INSTR(link_path, '/')+1) = n.nid ORDER BY created DESC";
			$result = db_query($sql);
			
			//run through ordered list assigning weight to menu items
			$i = 0;
			while ($r = db_fetch_array($result)) {
				db_query("UPDATE menu_links SET weight=".$i." WHERE mlid=".$r['mlid']);
				$i++;
			}
			//force rebuild of menu to pick up DB changes
	      	menu_rebuild();
	      }
	      break;
	  }
mschiff’s picture

Hi Stephen,

I hav a similar problem. Can you tell me where you placed this code? You wrote "inside hook_nodeapi", but in which file?

Or did you write your own module for that?

TIA
-mschiff