Drupal 6: print unaudited primary links and all children

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

I came to the conclusion that I want to print the menu in my page.tpl.php file ... so no block solutions, please.

I want to be able to scroll through the links of the main menu (AND children) and rewrite the output so that the Drupal class is not marked by default. The closest I found is an 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, the links are reprinted with the custom class UL and LI ... what GREAT! However, children are not printed. How do I extend this code so that all children are part of the list? NOTE. I do not want the children to be displayed only on the parent page, they should be present all the time. Otherwise, the drop-down menu that I planned is useless.

I sincerely thank you for this to reduce my gigantic headache!

+4
source share
2 answers

It's hard to influence the output once it reaches the .tpl page - you can better look for the template.php functions.

I used this to change the classes of my main 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;?> 
+5
source

I had to add <span> to my styling links, so I converted the links_ () theme to include / theme.inc. You can copy the function to your template.php template, rename it to yourthemename_links () and change it as needed. This function displays the tags ul, li, drupal_attributes, classes "first", "last", "active", etc. And affects the menu on the entire site.

You can also check the functions in include / menu.inc, including theme_menu_local_tasks () and menu_local_tasks (), if you need to display the primary and secondary in different ways. Marklnh

+1
source

Source: https://habr.com/ru/post/1309375/


All Articles