Drupal 6:打印纯正的主要链接和所有子链接 [英] Drupal 6: Printing Unadulterated Primary Links and all children

查看:23
本文介绍了Drupal 6:打印纯正的主要链接和所有子链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

世界上怎么可能?我发誓,我已经阅读了相当于 3 部百科全书的内容,但无济于事.我已经尝试过区域、page.tpl.php 和块内的解决方案.他们都没有给我我需要的东西……我知道还有很多其他人也需要这个!

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!

我得出的结论是,我想在我的 page.tpl.php 中打印菜单......所以请不要阻止解决方案.

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

我希望能够遍历主菜单链接(和子菜单)并重写输出,以便没有默认的 Drupal 类标记.我找到的最接近的是这个例子:

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; ?>

如您所见,正在使用自定义 UL 和 LI 类重印链接……太好了!然而,没有孩子被打印.我将如何扩展此代码以便所有孩子都成为列表的一部分?注意:我不希望孩子们只出现在他们的父页面上,他们必须一直在场.否则,我计划好的下拉菜单就没用了.

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!

推荐答案

一旦到达 page.tpl 就很难影响输出 - 您可能会更好地寻找 template.php 函数.

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">
";   
  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;
}

然后在 page.tpl.php 中我只是这样称呼它:

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;?> 

这篇关于Drupal 6:打印纯正的主要链接和所有子链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆