Drupal7: Tips and tricks on Menus


Parent Menu.

You can get the parent menu to which the current path belongs to using the function "menu_link_get_preferred". Lets say you have created a menu with name "ANDROID" and you have  listed a page/node under that menu. The following code returns true when you visit that page/node. You can use this technique to selectively display certain blocks only on some pages that belong to a target menu. 

 <?php
$menu = menu_link_get_preferred(current_path(), 'menu-android');
return ($menu['menu_name'] == 'menu-android');
?>

Place this code under the block's visibility criteria as shown bellow in Fig-1. The module "PHP filter" needs to be enabled for this to work. 

PHP filter used to selectively display blocks only on pages that  belong to a target menu
Fig-1