Sort nodes based on their position on a menu (views_handler_sort_menu_hierarchy?)
Hi all, I'd like to sort a view of nodes by the position of the nodes within the primary links menu. I found reference to a method that used computed field to calculate a weight. I'm not dead-set against using that, but thought this might be a good chance to write my first sort handler. I turned to the views docs and promptly found views_handler_sort_menu_hierarchy. I haven't delved much further except to triple-check that I don't see anything in the Views UI that seems to correspond to this sort handler. A quick grep of the class name indicates it's probably for books (which makes a lot of sense), though I can't think why it wouldn't also be open for other content types. So my questions are: 1. Any comments from folk about the best way to achieve ordering of nodes by their position in the menu? 2. Has anyone used views_handler_sort_menu_hierarchy? Can someone explain why it's not available by default (at least for a 'general' content type)? Thanks in advance, Andy . . . . . . . Andy Fowlston +44 (0)20 8747 5068 andrew@pedalo.co.uk Skype: andy.pedalo www.pedalo.co.uk This email is intended only for the above named addressee/s. This email may be confidential or legally privileged. If you have received this email and you are not a named addressee, you must not use, copy, distribute or disclose the email or any part of its contents or take any action in reliance on it. If you have received this email in error, please email the sender by replying to this message and delete it from your system. All reasonable precautions have been taken to ensure no viruses are present in this email. pedalo limited cannot accept responsibility for loss or damage arising from the use of this email or attachments and recommends that you subject these to your virus checking procedures prior to use. Any views or opinions presented are solely those of the author and not necessarily those of Pedalo Limited Please consider the environment before printing this email
The issue is that you cannot actually run a database query to sort the menu correctly, due to the nesting of children. But you can come close. (You also can't run a clean JOIN from {node} to {menu_links} without either a SQL calculation or a helper module. You might also try http://drupal.org/project/menu_node_views, which is the project that tries to consolidate work on Menu integration for Views, though it could use some work. If nothing else, you can likely steal its sort handler. On Tue, Jan 4, 2011 at 9:53 AM, Andrew Fowlston <Andrew@pedalo.co.uk> wrote:
Hi all,
I'd like to sort a view of nodes by the position of the nodes within the primary links menu. I found reference to a method that used computed field to calculate a weight. I'm not dead-set against using that, but thought this might be a good chance to write my first sort handler. I turned to the views docs and promptly found views_handler_sort_menu_hierarchy. I haven't delved much further except to triple-check that I don't see anything in the Views UI that seems to correspond to this sort handler. A quick grep of the class name indicates it's probably for books (which makes a lot of sense), though I can't think why it wouldn't also be open for other content types.
So my questions are:
1. Any comments from folk about the best way to achieve ordering of nodes by their position in the menu? 2. Has anyone used views_handler_sort_menu_hierarchy? Can someone explain why it's not available by default (at least for a 'general' content type)?
Thanks in advance,
Andy
. . . . . . . Andy Fowlston +44 (0)20 8747 5068 andrew@pedalo.co.uk Skype: andy.pedalo www.pedalo.co.uk
This email is intended only for the above named addressee/s. This email may be confidential or legally privileged. If you have received this email and you are not a named addressee, you must not use, copy, distribute or disclose the email or any part of its contents or take any action in reliance on it. If you have received this email in error, please email the sender by replying to this message and delete it from your system. All reasonable precautions have been taken to ensure no viruses are present in this email.
pedalo limited cannot accept responsibility for loss or damage arising from the use of this email or attachments and recommends that you subject these to your virus checking procedures prior to use. Any views or opinions presented are solely those of the author and not necessarily those of Pedalo Limited
Please consider the environment before printing this email
-- Ken Rickard agentrickard@gmail.com http://ken.therickards.com
Thanks Ken,
The issue is that you cannot actually run a database query to sort the menu correctly, due to the nesting of children.
Yeah, I understand from this page (http://drupal.org/node/141866) that 'We need to sort each subtree by weight and title in PHP' which I think is what you're referring to? I don't know how Views works internally - does that restriction of needing both a db query and some PHP post-processing make it a pain to implement as a view?
You might also try http://drupal.org/project/menu_node_views
Thanks, I'll do that. Andy . . . . . . . Andy Fowlston +44 (0)20 8747 5068 andrew@pedalo.co.uk Skype: andy.pedalo www.pedalo.co.uk This email is intended only for the above named addressee/s. This email may be confidential or legally privileged. If you have received this email and you are not a named addressee, you must not use, copy, distribute or disclose the email or any part of its contents or take any action in reliance on it. If you have received this email in error, please email the sender by replying to this message and delete it from your system. All reasonable precautions have been taken to ensure no viruses are present in this email. pedalo limited cannot accept responsibility for loss or damage arising from the use of this email or attachments and recommends that you subject these to your virus checking procedures prior to use. Any views or opinions presented are solely those of the author and not necessarily those of Pedalo Limited Please consider the environment before printing this email -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Ken Rickard Sent: 04 January 2011 16:40 To: development@drupal.org Subject: Re: [development] Sort nodes based on their position on a menu (views_handler_sort_menu_hierarchy?) The issue is that you cannot actually run a database query to sort the menu correctly, due to the nesting of children. But you can come close. (You also can't run a clean JOIN from {node} to {menu_links} without either a SQL calculation or a helper module. You might also try http://drupal.org/project/menu_node_views, which is the project that tries to consolidate work on Menu integration for Views, though it could use some work. If nothing else, you can likely steal its sort handler.
participants (2)
-
Andrew Fowlston -
Ken Rickard