SHOW:
|
|
- or go back to the newest paste.
1 | // Answer for question on Drupal Stack Exchange: | |
2 | // http://drupal.stackexchange.com/questions/27907/enable-a-nodes-menu-item-when-on-that-node | |
3 | ||
4 | // this is the template.php file!! | |
5 | // .... | |
6 | ||
7 | /** | |
8 | * @see http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_link/7 | |
9 | */ | |
10 | function YOURTHEMENAME_link($variables) { | |
11 | - | // in this example, I let "contact" and "node/9" links only be visible if the user is on these pages |
11 | + | // in this example, I let "node/425" link only be visible if the user is on this page |
12 | - | // and I let some other paths to be displayed at, see below... |
12 | + | $your_paths_to_hide_array = array('node/425'); // empty cache every time you change that |
13 | - | $your_paths_to_hide_array = array('contact', 'node/9'); // SUBSTITUTE IT with yours - empty cache every time you change that |
13 | + | $link_also_visible_on_paths = array(); // empty cache every time you change that |
14 | - | // these links will be visible only on their own pages - |
14 | + | |
15 | - | // but here you can define other paths where they can be visible at |
15 | + | |
16 | - | // if you don't want any other pages for these to be visible at, then |
16 | + | |
17 | - | // leave it empty (like this: array()), |
17 | + | |
18 | - | $link_also_visible_on_paths = array('node/3', 'any_other_path'); // SUBSTITUTE IT with your paths! - empty cache every time you change that |
18 | + | |
19 | if (!$element_can_be_visible) { | |
20 | return ''; | |
21 | } | |
22 | } | |
23 | return '<a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</a>'; | |
24 | } | |
25 | ||
26 | // .... |