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!
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;?>
I had to add a <span>
to my links for styling, so I overrode theme_links() in includes/theme.inc
You can copy the function to your template.php, rename it to yourthemename_links(), and modify it as needed.
This function outputs the ul, li tags, the drupal_attributes, classes of 'first', 'last', 'active', etc, and affects the menus throughout the site.
You may also want to check out the functions in includes/menu.inc, including theme_menu_local_tasks() and menu_local_tasks(), if you need to output the primary and secondary differently. MarkLNH
精彩评论