/** * Return header image based on the node id of the topmost active menu item * @return Absolute path to the image selected */ function get_header_image() { // Get the Page's Parent Menu Item $menuParent = menu_get_active_trail(); // background images based on node id's $node_imgs = array( 8 => 'header1.jpg', 12 => 'header2.jpg', 25 => 'header3.jpg', ); $header = 'default_header.jpg'; // Get the topmost menu element if (!empty($menuParent[1])) { $linkpath = $menuParent[1]['link_path']; if (!empty($linkpath)) { // search for node id in it's link_path preg_match("/node\/(\d+)/i", $linkpath, $match); if (!empty($match) && !empty($node_imgs[$match[1]])) $header = $node_imgs[$match[1]]; } } // return absolute path to the return base_path() . drupal_get_path('theme', 'MY_THEME_NAME') . '/images/header/' . $image; }