假设您可以访问php文件,那么这相当简单。
在生成菜单的模板中,修改wp_nav_menu 调用以指定container = FALSE
, 并在周围的HTML中手动提供容器和附加div。
在事先不知道代码的情况下,一种方法是按如下方式修改代码:
<nav id="my-menu"><div class="additional"></div>
<?php
// Replicate the args from the original code for the most part
$args = array(
\'theme_location\' => \'primary\', // Or whatever the original was
\'container\' => FALSE, // This tells it to not put a container around it
\'echo\' => TRUE, // again, whatever original was
// .. any other args from original code ...
);
wp_nav_menu($args);
?>
</nav>
EDIT:知道菜单需要在生成时进行修改,然后答案会发生一些变化:
您需要创建custom menu walker
基本原理如下。根据您的需要进行修改,请参考上面的Walker文章:
class Custom_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_el ( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
// Copy all the start_el code from source, and modify
}
function end_el( &$output, $item, $depth = 0, $args = array() ) {
// Copy all the end_el code from source, and modify
}
}
然后,在主题文件中,您可以调用wp\\u nav\\u菜单,如下所示:
wp_nav_menu(array(
\'theme_location\' => \'main\',
\'container\' => false,
\'menu_id\' => \'nav\',
\'depth\' => 1,
// This one is the important part:
\'walker\' => new Custom_Walker_Nav_Menu
));