`
haohappy2
  • 浏览: 317411 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Drupal:Using of Primary/Secondary Links for Building of Split-Level Menu

阅读更多

You need:

  • Create split-level menu.
  • The upper string is main items (first level), and sub-menu appears to the left of the selected item.
  • Parent item from main menu items is active when navigation through submenus.

 

Solution:

We need to form one menu creating its structure through selection of parent items, and then make the same menu primary and secondary in menu settings and add location of these menus in the form of ‘links’in  page.tpl.php.

Please follow step-by-step instructions to do this::

  1. GO to Administer → Site Building → Menus
  2. Create menu (you can create the required items just in primary links – menu is already created by default). To make menu split-level, select parents for menu items. Do nor create 2 different menus.
  3. Open Settings tab and select:
    Menu with primary links: your menu (Primary links)
    Menu with secondary links: your menu (Primary links)
  4. Insert the following code to page.tpl.php:
    For primary_links

<?php if (isset($primary_links)) { ?><?php print theme(‘links’, $primary_links) ?><?php } ?>

          For secondary_links:

<?php if (isset($secondary_links)) { ?><?php print theme(‘links’, $secondary_links) ?><?php } ?>

This method can be used for two-level hierarchy i.e. there are upper items and left items. No other submenus – secondary menu won’t show them.

We will use TemplatePHP  snippet from this page to create parent link with class="active". Insert the following code (without closing ?>) to template.php.

<?php
function phptemplate_links($links, $attributes = array()) {
  if (!count($links)) {
    return ”;
  }
  $level_tmp = explode(‘-’, key($links));
  $level = $level_tmp[0];
  $output = "<ul class=\"links-$level ".$attributes['class']. "\">\n";
  foreach ($links as $index => $link) {
    $output .= ‘<li’;
    if (stristr($index, ‘active’)) {
      $output .= ‘ class="active"’;
    }// frontpage AND current-link in menu is <front>
    elseif((drupal_is_front_page()) && ($link['href']==’<front>’)){
      $link['attributes']['class'] = ‘active’;//add class active to <li
      $output .= ‘ class="active"’;//add class active to <a
    }
    $output .= ">". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n";
  }
  $output .= ‘</ul>’;
  return $output;
}
?>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics