在wordpress中注册自定义菜单

时间:2015-01-11 10:33:11

标签: css wordpress menu

如何动态地在wordpress中注册此菜单?

我对wordpress中的动态菜单有问题

<nav id="nav">
<ul>
<li><a href="">Division</a>
<ul class="dropotron dropotron-level-0 center" style="-moz-user-select: none; position: absolute; z-index: 1000; left: 184.767px; top: 29px; opacity: 1; display: none;">
<li ><a style="display: block;" href="real-estate.html">Real Estate</a></li>
<li><a style="display: block;" href="waterpump.html">Water Pump</a></li>
<li ><a style="display: block;" href="fmcg.html">FMCG</a></li>
<li ><a style="display: block;" href="infrastructure.html">Infrastructure Project</a></li>
</ul>
</li>
<li ><a href="about-us.html">About Us</a></li>
<li class="break"><a href="career.html">Career</a></li>
<li ><a href="contact-us.html">Contact Us</a></li>
</ul>
</nav>

谢谢

1 个答案:

答案 0 :(得分:1)

我不确定当你说动态地在wordpress中注册这个菜单时,我完全理解你的意思,但如果你打算注册自定义菜单和显示它,请按照:

将此代码放在&#39; functions.php&#39; file :(如果您没有使用自己的主题,那么如果您还没有创建child theme

function register_your_menu() {
    register_nav_menu('your-menu-location',__( 'Your Menu Description' ));
}
add_action( 'init', 'register_your_menu' );

*注册新菜单 - 它将在管理面板上显示新菜单,因此请根据需要进行设置。

将此代码放在您希望菜单显示在主题上的位置,并自定义&#39; $ defaults&#39;你喜欢的设置(你可以在这里找到更多信息:http://codex.wordpress.org/Function_Reference/wp_nav_menu):

if ( has_nav_menu( 'your-menu-location' ) ) {   
    $defaults = array(
        'theme_location'  => 'your-menu-location',
        'menu'            => '',
        'container'       => 'div',
        'container_class' => '',
        'container_id'    => '',
        'menu_class'      => 'menu',
        'menu_id'         => '',
        'echo'            => true,
        'fallback_cb'     => 'wp_page_menu',
        'before'          => '',
        'after'           => '',
        'link_before'     => '',
        'link_after'      => '',
        'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
        'depth'           => 0,
        'walker'          => ''
    );

     wp_nav_menu( $defaults );
}