Closed (won't fix)
Project:
Views (for Drupal 7)
Version:
6.x-2.8
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
25 Sep 2008 at 03:14 UTC
Updated:
23 Aug 2022 at 13:47 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
merlinofchaos commentedCurrently Views doesn't offer a method to support by menu weight unless it's in a book outline. This might be something that can come in the future. Changing to feature request.
Comment #2
bartezz commentedsubscribing
Comment #3
k3vin commentedsubscribing
Comment #4
prom3theus commentedI'm using a custom solution with a CCK addon (computed field). Add a computed field to the content type what you need to orderable by menu weight, and use the below code as the computed field's 'computed code' value:
Check in the 'Display this field' and 'Store using the database settings below', use Data Type: int, set Data Length: 4 and save. After this, the saved field appears in views as a normal CCK field, but contents the associated node's menu item weight - now you can use as filter or ordering display.
Ofcourse you need to reupdate all content in this content type - this is just for fun :'(
And, BTW subscribing too :)
Comment #5
bartezz commentedThanx for sharing!!! Will try asap!
Comment #6
bartezz commentedCheck this: http://drupal.org/node/343299
Comment #7
dindon commentedsubscribing
Comment #8
marcuslim commentedI've written a very simple module that does this, while working on a project that requires sorting nodes according to their menu listing weight. Simply install the module, enable it, then in Views UI, under Sort Criteria, add the field 'Menu sorted nodes: Menu item weight' and choose ascending. Then the nodes for the view will be displayed according to their menu listing's weights, in ascending order from least weight to most weight.
Comment #9
bartezz commentedThanx!
Comment #10
Colin_T commentedThis looks like a duplicate of #110021: Add node weight to view's sort criteria
Comment #11
Colin_T commentedWhile it is a duplicate, the solution there doesn't work for me.
Comment #12
merlinofchaos commentedThat gives you no right to litter.
Comment #13
Colin_T commentedI was assuming that the duplicate I pointed out (assigned to 4.x & resolved by design) was a distinct entity from this one.
Should this work for 6.x?
Comment #14
marcuslim commentedYes, it works for 6.x. I tested it on Druapl 6.10.
Comment #15
Colin_T commentedmarcuslim - Thanks - hadn't properly realised I needed the weight module as well to achieve that.
Your views sort module seems to do the job nicely without requiring an extra field on the input forms, which seems a neater solution to me.
Comment #16
Matti303 commentedMany thanks for the module Marcuslim!! \o/
Comment #17
Plascual commentedThank you marcuslim! This is a very nice add-on.
But I have a litte problem with results order since I use Nice_Menus drop-down menus. The parent menu links to the same node as the first child menu, so views_menu_sort module seems to add one more result. That node appears twice in the views list.
I was wondering if it would be complicated to add settings to the module based on menu deepness ? Or maybe just eliminate those duplicates ?
Thanks in advance !
Plascual
EDIT: I realized that setting Distinct => 'Yes' in Views basic settings corrects this.
Comment #18
glennr commented#8 worked well for me too. Thanks, marcuslim.
Comment #19
manumilou commentedyes very useful module !
Comment #20
brightboldPerfect, marcuslim! Exactly what I needed.
Comment #21
leo pitt commented@marcuslim #8
Thanks for the views_menu_sort module.
Elegant, light-weight, and behaves exactly as I would have wanted.
Seems to work fine on Drupal 6.14 with Views 2.6
Comment #22
obrigado commentedMarcuslim, thanks for your great module. Any chance of starting a project page for it, or maybe merging it into Views 3?
Comment #23
monti commentedhave tried to use "views_menu_sort", provided by marcuslim (comment #8 above).
It is not working for me. I am not sure why. I use the weight module, which outside of views works properly. Inside views, I used marcuslim's function, but there is no impact. any direction, idea?
Cheers !
Comment #24
woodhous@email.unc.edu commentedHi Maruslim,
Thank you for the module. I am unable to set the weight on the nodes I need to sort in my view because they don't have a menu associated with them. The Page content type does not save the weight unless I assign a menu title. My menu nodes use a view reference to pull in related content based on taxonomy and I would like the ability to sort the nodes in the view reference. Is there any way to set the menu weight on a content item without it showing up on a menu.
Comment #25
bwoods commentedSweet, #8 worked for me as well. Thanks!
Comment #26
marcushenningsen commentedWorks beautifully! Thanks a lot. Changing status.
Marcus
Comment #27
merlinofchaos commentedErr, RTBC indicates that there is a patch. This module should probably be its own thing.
Comment #28
benmirkhah commentedAfter trying out many ways I like the #4 approach however "weight" alone will not be enough in a multi-level menu because then many items will have the same weight so instead I tweaked it to use p1 + p2 as explained here: http://drupal.org/node/141866
as well as depth and weight to get it working in perfect order for a 3 level menu...
$res = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE link_path = 'node/%s'", $node->nid));
$node_field[0]['value'] = is_array($res) ? (
str_pad($res['p1'], 4, '0', STR_PAD_LEFT).'-'.
str_pad($res['p2'], 4, '0', STR_PAD_LEFT).'-'.
str_pad($res['depth'], 4, '0', STR_PAD_LEFT).'-'.
str_pad(100+($res['weight']), 4, '0', STR_PAD_LEFT) ) : '0000-0000-0000-0000';
also in order to do a force update on all existing nodes to calculate the computed cck-field (varchar 20):
print "start ";
$result = db_query("SELECT nid FROM {node}");
while($nid = db_fetch_object($result)) {
$node = node_load($nid->nid);
node_save($node);
}
print "end ";
Comment #29
mattiasj commented#8 worked great for us, a lightweight and clean solution - thanks!
Comment #30
cleanthes commentedThanks @marcuslim. Worked first time, perfectly.
Comment #31
Nimo commentedThanks @marcuslim. Wonderful!
Comment #32
jdln commentedBenMirkhah's code from #28 works for me.
However im manually having to update all my nodes. How do I do a 'force update on all existing nodes'? What do I do with the code below?
Thanks
Comment #33
jdln commentedAnyone?
Comment #34
bartezz commentedCreate a node with a php filter instead of filtered or full html (need to enable a core module for this), copy paste code (need to put between
andtags. View the node et voila :) Backup first!Cheers
Comment #35
jdln commentedWorking. Thanks.
Comment #36
jdln commentedThe code from #28 has stopped working for me, and not for the first time. My CCK computed filed settings are identical to an older version of the site which is working fine, so I guess this code is unreliable?
By making the field visible I can see in views it doesn't have a value. On the node's display settings ive set the field to have a label and be visible but I cant see it on the node view page.
Ive experimented with 'Data Length' but what should this value be?
Ive created a support request in Computed Fields:
http://drupal.org/node/1005094
Comment #37
bartezz commentedHave you tried #8?
Comment #38
jdln commentedYes, but it doesn't work for a hierarchical menu.
Comment #39
bartezz commentedAh, that could be right indeed. I've only used it for first level menu nodes.... sorry.
Cheers
Comment #40
remaye commented#8 works (still) very well for me!
Thanks @marcuslim !
Is this module maintained ?
And is there any hope to have this feature integrated within Draggable Views ?
It would be great, in addition to sort items by menu weight, to have the ability to re-order the menu itself within the same view ...
Or is there any other solution to reorder menus without having to change the menu weight of each item in the node form or giving access to the menu administration itself ?
If any have a tip ... thanks!
Comment #41
squarecandy commented#8 works great. (single level menu) Thanks!!!
Comment #42
kaido.toomingas commentedThanks a lot @marcuslim and here are little changes to get this work with domain_access module. Worked fine with drupal 6.19 and views 2.x :).
Comment #43
jonaswouters commentedIs this available for 7?
Comment #44
jdln commentedSorry to backtrack, but is there a solution for a hierarchical menu? Is there some work around?
Thanks
Comment #45
ofktoubro commented#8 tnx
Comment #46
biwashingtonial commentedJust discovered this: http://drupal.org/project/menu_node_views
It provides quite a few Views handlers based on nodes' associated menu links, including sort (which does seem to work in hierarchical menus, based on a short test drive).
Comment #47
steven_kropp commentedAny ideas on how to take the module in #8 and make it work for Drupal 7, as far as I can see there is no way STILL to sort by menu weight for drupal 7... seems to me like a very necessary config.
Comment #48
mitsuko commentedThis is a version for Drupal 7. Menu node module is required. It provides in views :
- menu weight field
- menu weight sort filter
- menu link id filter to exclude particular entries (based on mlid)
Comment #49
Liaz commented#8 worked perfect and easy for me.
Thanks a lot @marcuslim
Comment #50
2pha#46 worked for me, drupal 7
Comment #51
jasonawantHello,
FWIW, for Drupal 7, the following modules provided menu: depth and menu: weight, which allowed me to sort view results according to their menu item hierarchy.
http://drupal.org/project/menu_node
http://drupal.org/project/menu_node_views
Jason
Comment #52
reallybigears commentedmarcuslim - thank you. I just installed your module and so far so good. Really can't believe this isn't a built in option. Excellent. thanks
Comment #53
ricancie commentedThanks soooooo much marcuslim!!!!
Comment #54
Wtower commentedAnother possibility for this is described in: http://drupal.stackexchange.com/questions/106538/how-to-sort-content-in-...
Comment #55
adamps commented@jdln and anyone else interested
As far as I can tell, none of these solutions work for a hierarchical menu, assuming like me you are looking for depth-first ordering.
Comment #56
nno commented#48 works great. Thank you very much
Comment #57
thomaswalther commentedMy solution, sorting all nodes in views like the sorting from their menu sorting: