Wordpress 创建菜单

问题描述 投票:0回答:1

我创建了一个新菜单,它显示得很好,但问题出在选择上,它会将我发送到不存在的页面或帖子,问题是,我想,.....更改格式输出,但我不这样做知道我该如何解决这个问题。

我的代码:

<?php

wp_create_nav_menu( 'Mobil Menu', array( 'slug' => 'theme_footer_mobil_menu' ) );

class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu
{
// don't output children opening tag (`<ul>`)
public function start_lvl(&$output, $depth){}
// don't output children closing tag    
public function end_lvl(&$output, $depth){}

public function start_el(&$output, $item, $depth, $args){

// add spacing to the title based on the current depth
$item->title = str_repeat("&nbsp;", $depth * 4) . $item->title;
// call the prototype and replace the <li> tag
// from the generated markup...
parent::start_el(&$output, $item, $depth, $args);

$output = str_replace('<li', '<option', $output);
}
// replace closing </li> with the closing option tag
public function end_el(&$output, $item, $depth){
$output .= "</option>\n";
}
}




wp_nav_menu(array(
"menu"=>"Mobil Menu",
'theme_location' => 'primary', 
'walker'         => new Walker_Nav_Menu_Dropdown(),
'items_wrap'     => '<select class="footer_menu_mobile" onChange="if(this.selectedIndex!=0) self.location=this.options[this.selectedIndex].value">%3$s</select>',
));

?> 

显示完美的菜单下拉菜单,但真正的问题是从选定的菜单启动 URL,该 URL 显示有空格且没有右侧

谢谢问候!

php wordpress drop-down-menu
1个回答
0
投票

为什么不使用简单的 css drop-dwo 菜单?

这是一个工作示例:

    .menu{
    border:none;
    border:0px;
    margin:0px;
    padding:0px 0px 0px 20px;
    font-family:"Arial";
    font-size:12px;
    font-weight:bold;
    list-style-type:none;

    }
.menu ul{
    height:35px;
    list-style:none;
    margin:0;
    padding:0;

     }
.menu li{
    float:left;
    padding:0px;
    list-style-type:none;

    }
.menu li a{
    background-color:#CC0000;
    color:#fff;
    display:block;
    font-weight:bold;
    line-height:35px;
    margin:0px;
    padding:0px 13px;
    text-align:center;
    text-decoration:none;
    list-style-type:none;
    }

    .menu li a:hover {
background-color:#000;
border-radius:3px;
    color:#fff;
    text-decoration:none;
    list-style-type:none;
    }
.menu ul li:hover a{
background-color:#000;
border-radius:-3px;
    color:#fff;
    text-decoration:none;
    list-style-type:none;
    }
.menu li ul{
background-color:#ccc;
color:#FFFFFF;
    display:none;
    height:auto;
    padding:0px;
    margin:0px;
    border:0px;
    position:absolute;
    width:150px;
    z-index:230;
    /*top:1em;*/
    }

.menu li ul li ul {
   margin-left:150px;
   margin-top:-35px;    
}

.menu li:hover > ul{
    display:block;

    }
.menu li li {
background:#000000;
    display:block;
    float:none;
    margin:0px;
    padding:0px;
    width:150px;
    }
.menu li:hover li a{
    background:none;

    }
.menu li ul a{
    display:block;
    height:35px;
    font-size:12px;
    font-style:normal;
    margin:0px;
    padding:0px 10px 0px 15px;
    text-align:left;
    }

.menu li ul li:hover {
    background:#CC0000;
    border:0px;
    color:#ffffff;
    text-decoration:none;
    }
.menu p {
    clear:left;
    } 

这是 php

<?php $defaults = array(
    'theme_location'  => 'Primary',
    'menu'            => 'your menu name', 
    'container'       => 'ul', 
    'container_class' => 'menu-{menu slug}-container', 
    'container_id'    => 'menu',
    'menu_class'      => 'menu', 
    'menu_id'         => 'menu-{menuslug}[-{increment}]',
    'echo'            => true,
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '',
    'link_before'     => '',
    'link_after'      => '',
    'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth'           => 0,
    'walker'          => ''
); ?>
              <?php wp_nav_menu( $defaults ); ?>
© www.soinside.com 2019 - 2024. All rights reserved.