doupingmao1903 2015-02-28 12:20
浏览 39

wordpress php函数中的wp菜单

I'm trying to create a simple nav in wordpress, however the wp_nav_menu parameters are ignored , am I missing something obvious?

I'm using a blank template called html5 blank. The Steps i've taken so are listed below

1) Register the menu in functions.php

2) From word press back end Create a menu called 'p' and assign pages

3) Give the menu a theme location

Registering and assigning menu location work fine , some but for some reason the wp_ parameters are ignored EG container , menu class, menu id etc...

If i inspect element, the container 'nav' is missing and the li items have default word press classes


BELOW is my code

Code in header.php

<?php html5blank_nav() ?>

Code in functions.php

function html5blank_nav()
    {
        wp_nav_menu(
        array(
            'theme_location'  => 'primary pete',    
            'menu'            => 'p'
            'container'       => 'nav',
            'container_class' => '',
            'container_id'    => '',
            'menu_class'      => 'slimmenu',
            'menu_id'         => 'navigation',
            'echo'            => true,
            'fallback_cb'     => 'false',
            'before'          => '',
            'after'           => '',
            'link_before'     => '',
            'link_after'      => '',
            'items_wrap'      => '<ul>%3$s</ul>',
            'depth'           => 0,
            'walker'          => ''
            )
        );
    }

// Register HTML5 Blank Navigation

  function register_html5_menu()
        {
            register_nav_menus(array( // Using array to specify more menus if needed
                'primary' => __('primary pete', 'Primary Menu'), 

                'sidebar-menu' => __('Sidebar Menu', 'html5blank'), 

                'extra-menu' => __('Extra Menu', 'html5blank') 
            ));
    }




// Remove the <div> surrounding the dynamic navigation to cleanup markup
function my_wp_nav_menu_args($args = '')
{
    $args['container'] = false;
    return $args;
}





// Remove Injected classes, ID's and Page ID's from Navigation <li> items
function my_css_attributes_filter($var)
{
    return is_array($var) ? array() : '';
}

// Remove invalid rel attribute values in the categorylist
function remove_category_rel_from_category_list($thelist)
{
    return str_replace('rel="category tag"', 'rel="tag"', $thelist);
}

// Add page slug to body class, love this - Credit: Starkers Wordpress Theme
function add_slug_to_body_class($classes)
{
    global $post;
    if (is_home()) {
        $key = array_search('blog', $classes);
        if ($key > -1) {
            unset($classes[$key]);
        }
    } elseif (is_page()) {
        $classes[] = sanitize_html_class($post->post_name);
    } elseif (is_singular()) {
        $classes[] = sanitize_html_class($post->post_name);
    }

    return $classes;
}

Many thanks, P

  • 写回答

1条回答 默认 最新

  • dongyi6183 2015-02-28 14:45
    关注

    When i try to reproduce this the menu with container_class => 'slimmenu' is shown. Are you sure when you add a class to the container_class parameter this is not shown in the inspector?

    Also noticed a missing comma after the parameter 'p' when i copied your code. But i don't think it will resolve your problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题