By ankycooper on
Hi
Lets say there is a menu Item called services, and under it there are lot of child menu items. Now i want to get a list of all children of services, possibly by views or custom php snippet.
Please Help
Hi
Lets say there is a menu Item called services, and under it there are lot of child menu items. Now i want to get a list of all children of services, possibly by views or custom php snippet.
Please Help
Comments
Can anyone Help Me Please
Can anyone Help Me Please
Here's some code
I recently had to handle a similar requirement, but was unable to find a way of doing it efficiently with Drupal's various menu_* functions.
After looking at menu_block & submenutree modules, and the _menu_update_parental_status() function to see how they determine menu children (they all directly access the DB), I wrote a couple custom functions in our project's module to help with this, here's what I came up with:
The first function returns rows from the menu_links table, with link_path = 'node/123', etc. The second function attempts to extract node IDs from the results of the first.
Then, I wrote a View that accepts NID arguments (with "Allow multiple terms"), setup a "Listing" content-type, then in the node type's template (node-listing.tpl.php) I can embed the View with a single line of code:
Views_argsort
One more thing... I ended up using views_argsort (http://drupal.org/project/views_argsort) to ensure the results came back from the View in the same order as the passed arguments.
Now I can simply create a Listing page, which automatically lists all child pages in the same order as the menu system, backed by the full power of Views for complete control and customization.
Works well
Hi Brian,
Thanks, these two functions worked very well for me. Like you, I could not find a function within the menu_* family of standard drupal functions to do this, but your solution addressed the problem very well.
Works great! Here is the
Works great!
Here is the Drupal 7 version for the code:
Here's the code to paste in D7 content with 'PHP filter' module
Thanks for the great code x_v -- i wanted to use it from within Drupal (not modifying any files) here's how I used his code with a few additional lines to call it.
Make sure you enable 'PHP filter' module (part of core, and disabled by default). Go to the content, and edit, make sure you select 'PHP Code' from the 'Text Format' options.
Paste this code (it's x_v's code, with the function calls and formatting made):
This will create a list of all the children titles that link to the content! No outside drupal messing required.