Language
  • English
  • Français
Drupal custom theming or module development price estimate calculator

Horizontal tree-like menus in Pixel Clever Tutorials

I would like to implement a menu system like the one in the top block of the main column in the Pixel Clever tutorials section, in which two horizontal menus at the bottom of the block seem to do duty for a menu tree, with the selected results (taxonomies?) being displayed on the blue menu bar at the top.

This is really great work in my humble opinion. If any how-to sharing is possible and appropriate, I would be most appreciative.

Making use of the Arguments in Views

Aaron's picture

That particular tabbed menu at http://www.PixelClever.com/drupal-tutorials was done with function in the template.php file that I called in the header of the view itself like so:

<?php
print tutorial_links();
?>

The function in the template.php looks as follows:

function tutorial_links(){
        $options = array(
                'attributes' => array (
                        'class' => 'active',
                ),
        );
       
        global $base_url;
        $path = $base_url . '/';
        $current = arg(0);
        if (arg(1)) {
                $one = arg(1);
        }
        else {
                $one = 'all';
        }
        if (arg(2)) {
                $two = arg(2);
        }
        else {
                $two = 'all';
        }
        $output    .= '<div id="tabsection">';
        $output    .= '<div class="tabwrap-1">';
        $output    .= '<div class="clearer"></div>';
        $output    .= '<ul class="tabs local-primary">';
        if (arg(2) == 2) {
                $output  .= '<li class="active">' . l(t('Drupal Administration'), $path . $current . '/' .  $one . '/2', $options) . '</li>';
        }
        else {
                $output  .= '<li>' . l(t('Drupal Administration'), $path . $current . '/' . $one . '/2') . '</li>';
        }
       
        if (arg(2) == 3) {
                $output  .= '<li class="active">' . l(t('Drupal Theming'), $path . $current . '/' . $one . '/3', $options) . '</li>';
        }
        else {
                $output  .=  '<li>' . l(t('Drupal Theming'), $path . $current . '/' . $one . '/3') . '</li>';
        }

        if (arg(2) == 4) {
                $output  .= '<li class="active">' . l(t('Drupal Module Development'), $path . $current . '/' . $one . '/4', $options) . '</li>';
        }
        else {
                $output  .= '<li>' . l(t('Drupal Module Development'), $path . $current . '/' . $one . '/4') . '</li>';
        }
  $arg2 = arg(2);
        if ((arg(2) == 'all') || empty($arg2)) {
                $output  .= '<li class="active">' . l(t('All Subjects'), $path . $current . '/' . $one . '/all', $options) . '</li>';
        }
        else {
        $output    .=  '<li>' . l(t('All Subjects'), $path . $current . '/' . $one . '/all') . '</li>';
        }
        $output    .= '</ul>';
        $output    .= '</div>'; // End tabwrap-1
       
       
        $output    .= '<div class="tabwrap-2">';
        $output    .= '<div class="clearer"></div>';
        $output    .= '<ul class="tabs local-secondary">';
        if (arg(1) == 5) {
                $output  .= '<li class="active">' . l(t('Basic'), $path . $current . '/5/' . $two , $options) .'</li>';
        }
        else {
                $output  .= '<li>' . l(t('Basic'), $path . $current . '/5/' . $two ) . '</li>';
        }
       
        if (arg(1) == 6) {
                $output  .= '<li class="active">' . l(t('Intermediate'), $path . $current . '/6/' . $two , $options) .'</li>';
        }
        else {
                $output  .= '<li>' . l(t('Intermediate'), $path . $current . '/6/' . $two ) . '</li>';
        }

        if (arg(1) == 7) {
                $output  .= '<li class="active">' . l(t('Advanced'), $path . $current . '/7/' . $two , $options) . '</li>';
        }
        else {
                $output  .= '<li>' . l(t('Advanced'), $path . $current . '/7/' . $two ) . '</li>' ;
        }
        $arg1 = arg(1);
        if ((arg(1) == 'all') || empty($arg1)) {
                $output  .= '<li class="active">' . l(t('All Levels'), $path . $current .  '/all/' . $two, $options) . '</li>' ;
        }
        else {
                $output  .= '<li>' . l(t('All Levels'), $path . $current . '/all/' . $two ) . '</li>' ;
        }
       
       
        $output    .= '</ul>';
        $output    .= '<div class="clearer"></div>';
        $output    .= '</div>'; // End tabwrap-2
        $output    .= '</div>'; // End tabsection
        return $output;
}

The view for that page accepts two arguments one a term id (tid) from one vocabulary, another a tid from a different category. The main trick here is that the links themselves are made to change where they link to depending on which category the user is currently viewing. This is achieved by calling the arg() function. Since I knew that the arguments in question were arguments 1 and 2 I got the values for those arguments with arg(1) and arg(2). If the argument was listed as "all" (which is the wildcard for that view) then all is inserted into the link.

The tabs themselves make use of the same html and CSS as the normal tabs on the site to avoid double coding.

Thanks for the help

Thanks Aaron,

I appreciate that someone with your talent has taken the time to share some of your knowledge.

-Robert

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Ask a question related to Drupal development or administration