我一直在学习将HTML转换为WordPress,并希望将其转换为如下类:
<div class="mainmenu pull-left">
<ul class="nav navbar-nav collapse navbar-collapse">
<li><a href="index.html" class="active">Home</a></li>
<li class="dropdown"><a href="#">Shop<i class="fa fa-angle-down"></i></a>
<ul role="menu" class="sub-menu">
<li><a href="shop.html">Products</a></li>
<li><a href="product-details.html">Product Details</a></li>
<li><a href="checkout.html">Checkout</a></li>
<li><a href="cart.html">Cart</a></li>
<li><a href="login.html">Login</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">Blog<i class="fa fa-angle-down"></i></a>
<ul role="menu" class="sub-menu">
<li><a href="blog.html">Blog List</a></li>
<li><a href="blog-single.html">Blog Single</a></li>
</ul>
</li>
<li><a href="404.html">404</a></li>
<li><a href="contact-us.html">Contact</a></li>
</ul>
</div>
这就是我所做的:
if ( ! function_exists( \'mytheme_setup\' ) ) :
function wpflex_setup() {
register_nav_menus( array(
\'primary\' => \'Primary Menu\'
) );
}
endif;
wp_nav_menu( array(
\'theme_location\' => \'top-menu\',
\'container\' => \'\',
\'menu_class\' => \'mainmenu pull-left\',
) );
如何为添加类
ul
?
SO网友:Ted
Wordpress创建的默认页面菜单与活动菜单不同,这些菜单是您在后端创建和分配的。没有直接的方法将类添加到页面菜单中的UL中,但还有其他方法。尝试将其添加到函数中。php
function add_id_and_classes_to_page_menu( $ulclass ) {
return preg_replace( \'/<ul>/\', \'<ul id="main-menu" class="nav navbar-nav collapse navbar-collapse">\', $ulclass, 1 );
}
add_filter( \'wp_page_menu\', \'add_id_and_classes_to_page_menu\' );
请记住,这将替换任何现有的id和类,因此我在上面的示例中重新添加了它们。我还添加了一个id=“主菜单”以完成操作。