简体   繁体   English

Drupal 7中的“自定义移动菜单”无法访问子链接

[英]Custom Mobile Menu in Drupal 7 can't access child links

My company took over the maintenance of a website and I am trying to determine how to properly get both the top-level (parent) links as well as the child links. 我的公司接管了网站的维护工作,我正在尝试确定如何正确获取顶级(父级)链接和子级链接。 The code that was being used is: 使用的代码是:

 <div id="monav">
<ul>
  <?php
$mobile_menu = menu_navigation_links('menu-mobile-nav');
print theme('links__menu_mobile_nav', array('links' => $mobile_menu));

  ?>
  </ul>

This only spits out the top-level. 这只会吐出顶层。 I have been digging through forums and code trying to find the correct way to get the child links. 我一直在浏览论坛和代码,试图找到获取子链接的正确方法。 Can you point me in the right direction oh wise Drupal gurus? 你能为我指出正确的方向吗?明智的Drupal大师?

Note: setting the parent link to "Show as expanded" does not work. 注意:将父链接设置为“显示为展开”不起作用。

I ended up using this code: 我最终使用了以下代码:

In template.php I have 在template.php中,我有

//Render Mobile
function drive_menu_tree__menu_mobile_nav($variables){
    return '<ul class="" id="">' . $variables['tree'] . '</ul>';
}


function drive_menu_links__menu_mobile_nav($variables) {
    $element = $variables['element'];
    $sub_menu = '';

    if ($element['#below']) {
        $sub_menu = drupal_render($element['#below']);
    }
    $output = l($element['#title'], $element['#href'], $element['#localized_options']);
    return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

Then I display the menu in page.tpl.php using: 然后我使用以下命令在page.tpl.php中显示菜单:

print drupal_render(menu_tree_output(menu_tree_all_data('menu-mobile-nav')));

SOURCE: How to display a menu in a template file? 消息来源: 如何在模板文件中显示菜单?

Update: 更新:

The above code was spitting out an error so instead I am doing this. 上面的代码吐出了一个错误,所以我正在这样做。

template.php in the theme_preprocess_page(&$vars) function theme_preprocess_page(&$ vars)函数中的template.php

//Render main menu 
$main_menu_tree = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
$vars['main_menu'] =  $main_menu_tree;

Then I am displaying the menu in page.tpl.php using 然后我使用显示在page.tpl.php中的菜单

  <div id="monav">
  <?php
        print render($main_menu);
    ?>
</div>

To make this menu mobile I added the following jquery 为了使此菜单移动,我添加了以下jQuery

(function ($) {

$(document).ready(function(){
//Mobile Navigation
$('#nav-toggle').click(function(e) {
  $('#monav').toggle();
});
$('#monav li.expanded > a').attr("href", "#");
 $("#monav li.expanded").click(function() {

  $(this).find('.menu').toggle();

   });
 });

})(jQuery);

Note I had to hide this in my css 注意我必须将其隐藏在CSS中

#monav ul.menu li.expanded .menu{
display:none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM