如何在创建div的函数中放置div

时间:2013-01-24 作者:Anders Kitson

我想知道为什么不在bones\\u main\\u nav函数html代码之后使用menuTab div,而将其输出并注入其中。

我有以下功能

// the main menu
function bones_main_nav() {
    // display the wp3 menu if available
    wp_nav_menu(array(
        \'container\' => false,                           // remove nav container
        \'container_class\' => \'menu clearfix\',           // class of container (should you choose to use it)
        \'menu\' => __( \'The Main Menu\', \'bonestheme\' ),  // nav name
        \'menu_class\' => \'nav top-nav clearfix\',         // adding custom nav class
        \'theme_location\' => \'main-nav\',                 // where it\'s located in the theme
        \'before\' => \'\',                                 // before the menu
        \'after\' => \'\',                                  // after the menu
        \'link_before\' => \'\',                            // before each link
        \'link_after\' => \'\',                             // after each link
        \'depth\' => 0,                                   // limit the depth of the nav
        \'fallback_cb\' => \'bones_main_nav_fallback\'      // fallback function
    ));
} /* end bones main nav */
以及以下html/php

<nav role="navigation">
                        <?php bones_main_nav(); ?>
                        <div id="menuTab">
                            <a href="#"><i class="icon-reorder"></i></a>d
                        </div>
                    </nav>
UPDATEbones\\u main\\u nav函数生成以下html,我已经对menutab div的位置进行了注释。

<div class="nav footer-nav clearfix">
<ul>
<li>home</li>
</ul>
<div id="menuTab"></div>**<!--THIS IS WHERE I WANT MENU TAB TO GO-->**
</div>

1 个回复
SO网友:Wyck

我认为您不能使用该函数并执行该操作,但我对bones_main_nav . 使用默认WordPress函数(bones函数正在包装该函数)将仅输出<ul>...menu items... </ul>, 然后一个简单的方法就是将其包装到模板文件中。

例如:

 $defaults = (array(
        \'container\' => false,                          
        \'menu\' => __( \'The Main Menu\', \'bonestheme\' ),  // nav name
        \'menu_class\' => \'nav top-nav clearfix\',         // adding custom nav class
        \'theme_location\' => \'main-nav\',                 // where it\'s located in the theme
        \'before\' => \'\',                                 // before the menu
        \'after\' => \'\',                                  // after the menu
        \'link_before\' => \'\',                            // before each link
        \'link_after\' => \'\',                             // after each link
        \'depth\' => 0,                                   // limit the depth of the nav
        \'fallback_cb\' => \'bones_main_nav_fallback\'      // fallback function
        ));
您的模板标记为:

<div class="nav footer-nav clearfix">
<?php wp_nav_menu( $defaults ); ?>
<div id="menuTab"></div>**<!--THIS IS WHERE I WANT MENU TAB TO GO-->**
</div>
通过代码的一种更复杂的方法是使用Menu Walker

结束