The whole project can be found here Github .
I added a dynamic menu on my navigation bar placed in the header. For some reason I can't figure out how to link the dynamic menu with either a class or an ID defined in my style.css file.
For some reason, neither the 'menu_class' or the 'menu_id' seem to work.
Here the menu in the header.php file:
<!-- 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-->
The function.php file:
/*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');
如果渲染方法搞砸了,那么您始终可以使用.nav > div
,无论是否带有伪类(如:nth-of-type(1)
或者使用第二种方法: .nav:nth-child(1)
作为第一个子代的查询在div.nav
内部?
If you want to add class, try to add it within wp_nav_menu() you wrote like this: 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' ) );
or you can apply selectors I wrote in first answer to your CSS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.