Posted by akki123 on September 3, 2012 at 1:26pm
I have a menu item at second level in main-menu called "news" ( node/15 ) , now I want to show listing of all news on this page. I want to show "news" menu item highlighted after user click on list page. These listed news will not show in any menu.
How to do this?
I tried various tricks.
http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_tree_set_path/7
http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_set_active_item/7
http://drupal.org/node/520106
What code should be added?
Where it should be added?
drupal version is 7.12
Thanks
Comments
If you need listing of all
If you need listing of all news, you need to create view for that. This view should be page, not block. And then create menu item for that view in you main-menu. You have that option in views settings.
Not what I want!
Thanks for reply.
Perhaps I unable to explain it clearly.
News listing page is already there and working as expected.
Say I have menu "news" under "media".
Media->News
On this page , I have three news,
News item 1
News item 2
News item 3
These nodes are not associated with any menu item. But when user click on "News item 1", I want to show
Media->News menu as active.
I tried
menu_set_active_trial
menu_tree_set_path()
in theme_preprocess_page() in template.php
akki
Now I see your problem. In
Now I see your problem. In this scenario I use Menu Trail By Path module. It is very simple and works well. Just take care of your paths; if path for news listing page is /media/news, configure nodes of content type "News" (with Pathauto module) to autocreate path media/news/[node:title].
I tried this
this module Menu Trail By Path module and found no configuration option or read me file.
And I an not alone who is facing difficulty to configure this module
I will try your suggestion with this module.Yes, it works well too.Strangely, I want to do this with template.php in theme directory or override node.tpl.php but seems menu is already built and we can not change it in these files.
I use hook_node_view in custom module and it solved all issues. menu_tree_set_path() use active-trail class so you may need to modify css.
function mymodule_node_view($node, $view_mode, $langcode) {if($node->type == 'news') {
menu_tree_set_path('main-menu', 'node/11');
}
}
akki