我是我的Wordpress(与Buddypress)应用程序我使用一个响应主题。不过,如果屏幕宽度为< = 768px,我已将菜单更改为选择框下拉菜单。选择框菜单不加载页面
你可以在下面看到我的想法,这是通过使用两个wp_nav_menu完成的,其中一个(在walker的帮助下)创建菜单作为选择下拉菜单(当然借助responsive.css )。
但是,我在这里一个问题,我需要帮助:
的选择框menulooks正确的,但如果我在菜单没有什么改变选项实际情况(即页面没有改变)。怎么来的?
的header.php:
<div id="navigation" role="navigation">
<?php
<?php
wp_nav_menu(array(
'container' => false,
'menu_id' => 'nav',
'theme_location' => 'primary',
'fallback_cb' => 'bp_dtheme_main_nav')
);
wp_nav_menu(array(
'container' => false,
'menu_id' => 'nav',
'theme_location' => 'primary', // your theme location here
'walker' => new Walker_Nav_Menu_Dropdown(),
'items_wrap' => '<select>%3$s</select>',
'fallback_cb' => 'bp_dtheme_main_nav'
));
class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{
function start_lvl(&$output, $depth){
$indent = str_repeat("\t", $depth);
}
function end_lvl(&$output, $depth){
$indent = str_repeat("\t", $depth);
}
function start_el(&$output, $item, $depth, $args){
$item->title = str_repeat(" ", $depth * 4).$item->title;
parent::start_el(&$output, $item, $depth, $args);
$output = str_replace('<li', '<option', $output);
}
function end_el(&$output, $item, $depth){
$output .= "</option>\n";
}
} ?>
</div>
编辑:我意识到,这呈现的选择选项不包含任何值,所以我不能抢重定向的期权价值。代码显然有些问题,但是什么?
我已经为自己工作了,这比我之前使用的解决方案要更加诚实:)看到我的修改后的答案。 – McNab 2013-03-03 15:10:16