简体   繁体   English

WordPress主题-如何设置菜单样式?

[英]Wordpress theme - how to style menu?

I am pretty new to Wordpress theme development and I can't find how to style properly my navigation menu. 我对Wordpress主题开发还很陌生,我找不到如何正确设置导航菜单的样式。

Here is my raw html code: 这是我的原始html代码:

  <!-- Navigation --> <nav class="navbar navbar-default navbar-custom navbar-fixed-top"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header page-scroll"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="<?php bloginfo('url'); ?>"><?php bloginfo('name');?></a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav navbar-right"> <li> <a href="index.html">Home</a> </li> <li> <a href="about.html">About</a> </li> <li> <a href="post.html">Sample Post</a> </li> <li> <a href="contact.html">Contact</a> </li> </ul> </div> <!-- /.navbar-collapse --> </div> <!-- /.container --> </nav> 

What should I do in order to get all the classes and structure from the above code? 为了从上述代码中获取所有类和结构,我应该怎么做? I tried with wp_nav_menu( array('container_class' => 'navbar navbar-default navbar-custom navbar-fixed-top') ); 我尝试了wp_nav_menu(array('container_class'=>'navbar navbar-default navbar-custom navbar-fixed-top')); , but it is not working that way. ,但这种方式无法正常工作。

What you are looking to do is to create a custom walker class: 您正在寻找的是创建一个自定义的walker类:

https://codex.wordpress.org/Class_Reference/Walker https://codex.wordpress.org/Class_Reference/Walker

or to cycle through the navigation elements using wp_get_nav_menu_items: 或使用wp_get_nav_menu_items循环浏览导航元素:

https://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items https://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items

I don't know how much PHP programming experience you have, but both methods will be involved. 我不知道您有多少PHP编程经验,但是两种方法都会涉及。 Your easiest bet, I think, would be to use wp_get_nav_menu_items and go from there. 我认为,最简单的选择就是使用wp_get_nav_menu_items然后从那里开始。

Try it out and let me know if you run into problems. 尝试一下,让我知道是否遇到问题。 If you do, show the code you've tried and I'll be happy to help revisit the problem! 如果这样做,请显示您尝试过的代码,我们将很乐意帮助您重新解决问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM