Search code examples
drupalmenudrupal-6submenu

Drupal 6: Printing Unadulterated Primary Links and all children


How in the WORLD is possible? I swear, I've read the equivalent of 3 encyclopedias to no avail. I've tried solutions within regions, page.tpl.php and blocks. None of them give me what I need... and I know there are so many other people that need this too!

I've come to the conclusion that I want to print out the menu within my page.tpl.php ... so no block solutions, please.

I want to be able to loop through the primary menu links (AND children) and rewrite the output so that there's no default Drupal class tagging. The closest I've found is this example:

<?php if (is_array($primary_links)) : ?>
<ul id="sliding-navigation">
<?php foreach ($primary_links as $link): ?>
<li class="sliding-element"><?php        
        $href = $link['href'] == "<front>" ? base_path() : base_path() . drupal_get_path_alias($link['href']);
        print "<a href='" . $href . "'>" . $link['title'] . "</a>";            
        ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>

As you can see, links are being reprinted with a custom UL and LI class ... that's GREAT! However, no children are being printed. How would I extend this code so that all children are a part of the list? NOTE: I don't want the children to only appear on their parent page, they must be present all the time. Otherwise, the drop-down menu I have planned is useless.

I sincerely thank you in advance to lessening my gargantuan headache!


Solution

  • It's hard to affect the output once it's got as far as the page.tpl - you might do better looking for template.php functions.

    This is one I used to alter the classes of my primary links:

    function primary_links_add_icons() {
      $links = menu_primary_links();
      $level_tmp = explode('-', key($links));
      $level = $level_tmp[0];
      $output = "<ul class=\"links-$level\">\n";   
      if ($links) {
        foreach ($links as $link) {
            $link = l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']);
            $output .= '<li class="sublevel">' . $link .'</li>';
        };
        $output .= '</ul>';
      }
      return $output;
    }
    

    And then in page.tpl.php I just called it like this:

    <?php if ($primary_links) :?>
        <?php print '<div id="menu">'; ?>
        <?php print primary_links_add_icons(); ?>
        <?php print '</div>'; ?>
    <?php endif;?>