snipt

Ctrl+h for KB shortcuts

PHP

Load a custom menu or submenu in Drupal 7

1
2
3
4
5
6
7
8
// get submenu
$vars['submenu'] = FALSE;
$menu_tree = menu_tree('main-menu'); 
$active_trail = menu_get_active_trail();
$active_trail_mlid = $active_trail[1]['mlid'];
if( array_key_exists($active_trail_mlid, $menu_tree) ) {
  $vars['submenu'] = $menu_tree[$active_trail_mlid]['#below'];	
}
https://snipt.net/embed/e560526180d548c806f6080af510ba79/
/raw/e560526180d548c806f6080af510ba79/
e560526180d548c806f6080af510ba79
php
PHP
8
2019-08-16T05:41:30
True
False
False
/api/public/snipt/36008/
load-a-custom-menu-or-submenu-in-drupal-7
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">// get submenu</span> </span><span id="L-2"><a name="L-2"></a><span class="x">$vars[&#39;submenu&#39;] = FALSE;</span> </span><span id="L-3"><a name="L-3"></a><span class="x">$menu_tree = menu_tree(&#39;main-menu&#39;); </span> </span><span id="L-4"><a name="L-4"></a><span class="x">$active_trail = menu_get_active_trail();</span> </span><span id="L-5"><a name="L-5"></a><span class="x">$active_trail_mlid = $active_trail[1][&#39;mlid&#39;];</span> </span><span id="L-6"><a name="L-6"></a><span class="x">if( array_key_exists($active_trail_mlid, $menu_tree) ) {</span> </span><span id="L-7"><a name="L-7"></a><span class="x"> $vars[&#39;submenu&#39;] = $menu_tree[$active_trail_mlid][&#39;#below&#39;]; </span> </span><span id="L-8"><a name="L-8"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
d7, menu, submenu