douyanning3724 2010-02-09 21:59
浏览 71
已采纳

需要在WordPress菜单中为子UL添加选择器

In order to make use of a particular jQuery menu in WordPress, I need the child UL (dropdown part of the menu) to have a selector added to it (third line, below):

<ul class="dropdown">
    <li>the first list item
        <ul class="sub_nav">
            <li>child list item</li>
        </ul>
    </li>
</ul>

Note: I left out the link code for greater clarity.

I'm not a coder. My PHP and javascript skills are of the copy-paste-tinker variety. Other forums have yielded lots of vague suggestions, but no solutions. I'm open to other solutions, but I'd like to solve it in one of two places:

  1. Modify <#?php wp_list_pages('title_li=&depth=2'); ?> in the theme header.php file
    [had to add # to code bit to make it show up]

  2. Add a function in the theme functions.php file

  • 写回答

2条回答 默认 最新

  • douchang6770 2010-02-10 16:12
    关注

    Mike Little of zed1.com furnished a solution on a LinkedIn forum:

    In the theme functions file:

    class My_Walker_Page extends Walker_Page {
    function start_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    if (0 == $depth)
    $output .= " $indent<ul class=\"sub_menu\"> ";
    else
    $output .= " $indent<ul> ";
    }
    }

    In the header file where menu is to appear:

    <ul class="dropdown"><?php $walker = new My_Walker_Page;
    wp_list_pages(array('title_li'=>'', 'depth' => 2, 'walker' => $walker)); ?></ul>

    Mucho gracias to Mike Little, who was a founding member of the WordPress team.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制