整个项目可以在Github找到。
我在标题中的导航栏上添加了一个动态菜单。出于某种原因,我无法弄清楚如何将动态菜单与我的style.css文件中定义的类或ID相关联。
出于某种原因,'menu_class'或'menu_id'似乎都不起作用。
这里是header.php文件中的菜单:
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<!--Container of my link that are on the far right, they collapse with a small screen-->
<ul class="nav navbar-nav navbar-right">
<!--This code inject the dynamic menu inside thge av bar-->
<!-- The Dynamic menu is managed in the admin section of word press-->
<?php
wp_nav_menu(
array(
/*must have this link to function.php
*In function.php we defined this menu 'alphamenu'*/
'theme_location' => 'top-right-menu',
/*this line of code removes the default menu appearence*/
'container' => false,
/*this line makes the menu with the same layout specified above
*(same as link 1 and 2)*/
'items_wrap' => '%3$s',
/*CSS class applied to the menu*/
'menu_class' => 'nav navbar-nav custom-head-foot',
'menu_id' => 'custom-dynamic-menu'
)
);
?>
</ul> <!--dynamic menu unordered list-->
</div> <!--dynamic menu div-->
function.php文件:
/*Function to register a custom menu for the admin section
*This resurces was taken from the wordpress codex*/
function custom_theme_setup() {
/*Registered a custom primary navigation menu*/
register_nav_menus (
array( 'alphamenu', __( 'Primary Menu 123') )
);
/*Add theme support for title tag*/
add_theme_support( 'title-tag' );
}
/*Hooking in the function "custom_theme_setup()" after the theme is setup
*surce: wordpress plugin api hooks*/
add_action( 'after_setup_theme', 'custom_theme_setup');
答案 0 :(得分:0)
如果渲染方法搞砸了你总是可以使用.nav > div
有或没有像:nth-of-type(1)
这样的伪类,或者第二种方式:.nav:nth-child(1)
作为{{1}内第一个孩子的查询}}?
答案 1 :(得分:0)
如果你想添加类,尝试在你写的wp_nav_menu()中添加它:
wp_nav_menu(
array(
/*must have this link to function.php
*In function.php we defined this menu 'alphamenu'*/
'theme_location' => 'top-right-menu',
/*this line of code removes the default menu appearence*/
'container' => false,
/*this line makes the menu with the same layout specified above
*(same as link 1 and 2)*/
'items_wrap' => '%3$s',
/*CSS class applied to the menu*/
'menu_class' => 'nav navbar-nav custom-head-foot **add_your_class_within_single_quotes**',
'menu_id' => 'custom-dynamic-menu'
)
);
或者您可以应用我在第一次回答CSS时写的选择器。