dongyou2279 2013-10-31 10:32
浏览 83
已采纳

更改wordpress中的子菜单类

When using wp_nav_menu in my theme, I want to change Worpdress' default sub-menu class for items that contain a child list (to dropdown to fit for the Foundation framework).

I have reviewed this post on the topic but I cannot seem to get it to function correctly.

In my functions.php file I have inserted:

class My_Sub_Menu extends Walker_Nav_Menu {
  function start_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    $output .= "
$indent<ul class=\"dropdown\">
";
  }
}

And in my header.php file I have:

<?php
    $defaults = array(
        'theme_location'  => 'header-nav',
        'menu_class'      => 'right',
        'walker'          => new My_Sub_Menu(),
        'container'       =>  false
    );
    wp_nav_menu( $defaults );
?>

But nothing occurs. Am I misunderstanding where to insert the code?

  • 写回答

1条回答 默认 最新

  • du8791069 2013-10-31 11:33
    关注

    Is it because you haven't specified an end_lvl for your class My_Sub_Menu extends Walker_Nav_Menu?

    class My_Sub_Menu extends Walker_Nav_Menu {
      function start_lvl(&$output, $depth) {
        $indent = str_repeat("\t", $depth);
        $output .= "
    $indent<ul class=\"dropdown\">
    ";
      }
      function end_lvl(&$output, $depth) {
        $indent = str_repeat("\t", $depth);
        $output .= "$indent</ul>
    ";
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答