WordPress菜单和bootstrap选项卡集成

时间:2016-12-21 14:02:42

标签: php wordpress twitter-bootstrap toggleclass

我正在使用bootstrap构建一个WordPress博客,我使用了wp_bootstrap_navwalker php来启用我的wordpress菜单以传递到我的引导代码中

 <div id="navbar" class="collapse navbar-collapse" style="background-color: #333;">
    <div class="container">
        <ul class="nav navbar-nav">
            <?php
            /* Primary navigation */
            wp_nav_menu(array(
                    'menu' => 'Primary Menu',
                    'theme_location' => 'locations-primary',
                    'depth' => 2,
                    'container' => false,
                    'container_class'   => 'collapse navbar-collapse',
                    'container_id'      => 'bs-example-navbar-collapse-1',
                    'menu_class' => 'nav navbar-nav',
                    'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
                    'walker'            => new wp_bootstrap_navwalker())
            );
            ?>
        </ul>
    </div>
</div>

这很好用,虽然现在我正在尝试使用上面的菜单系统构建一个标签菜单,如此

 <div class="container">
                            <ul class="nav navbar-nav">
                                <div class="row text-center" id="tabs">
                                    <?php
                                    /* Secondary navigation */
                                    wp_nav_menu(array(
                                            'menu' => 'Secondary Menu',
                                            'theme_location' => 'locations-secondary',
                                            'depth' => 2,
                                            'container' => false,
                                            'container_class' => 'collapse navbar-collapse',
                                            'container_id' => 'bs-example-navbar-collapse-1',
                                            'menu_class' => 'nav navbar-nav',
                                            'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
                                            'walker' => new wp_bootstrap_navwalker())
                                    );
                                    ?>
                                </div>
                            </ul>
                        </div>

和标签内容

      <div class="row text-center" id="tabs">
            <?php get_template_part('advicecentre_bar', get_post_format());>
            <div class="tab-content">
                <div class="tab-pane active" id="tab1">
                    <?php
                    $id = 177;
                    $post = get_post($id);
                    $title = apply_filters('the_title', $post->post_title);
                    $content = apply_filters('the_content', $post->post_content);
                    echo '<h1>' . $title . '</h1><hr>';
                    echo $content;
                    ?>
                </div>

                <div class="tab-pane" id="tab2">
                    <?php
                    $id = 2;
                    $post = get_post($id);
                    $title = apply_filters('the_title', $post->post_title);
                    $content = apply_filters('the_content', $post->post_content);
                    echo '<h1>' . $title . '</h1><hr>';
                    echo $content;
                    ?>
                </div>

                <div class="tab-pane" id="tab3">
                    <?php
                    $id = 168;
                    $post = get_post($id);
                    $title = apply_filters('the_title', $post->post_title);
                    $content = apply_filters('the_content', $post->post_content);
                    echo '<h1>' . $title . '</h1><hr>';
                    echo $content;
                    ?>
                </div>
</div>
</div>

在wordpress菜单中cms我已经创建了自定义链接并给出了URL #tab1这样的网址但是我缺少data-toggle="tab"以使标签正常工作,我无法通过以下方式看到这样做的方法CMS剂量任何人都知道如何使这项工作。

更新

好的,我正在尝试编辑以下代码,说明menu_class是导航导航标签,然后在data-toggle="tab"中附加<a>需要一些帮助吗

public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
        $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

        /**
         * Dividers, Headers or Disabled
         * =============================
         * Determine whether the item is a Divider, Header, Disabled or regular
         * menu item. To prevent errors we use the strcasecmp() function to so a
         * comparison that is not case sensitive. The strcasecmp() function returns
         * a 0 if the strings are equal.
         */
        if ( strcasecmp( $item->attr_title, 'divider' ) == 0 && $depth === 1 ) {
            $output .= $indent . '<li role="presentation" class="divider">';
        } else if ( strcasecmp( $item->title, 'divider') == 0 && $depth === 1 ) {
            $output .= $indent . '<li role="presentation" class="divider">';
        } else if ( strcasecmp( $item->attr_title, 'dropdown-header') == 0 && $depth === 1 ) {
            $output .= $indent . '<li role="presentation" class="dropdown-header">' . esc_attr( $item->title );
        } else if ( strcasecmp($item->attr_title, 'disabled' ) == 0 ) {
            $output .= $indent . '<li role="presentation" class="disabled"><a href="#">' . esc_attr( $item->title ) . '</a>';
        } else {

            $class_names = $value = '';

            $classes = empty( $item->classes ) ? array() : (array) $item->classes;
            $classes[] = 'menu-item-' . $item->ID;

            $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );

            if ( $args->has_children )
                $class_names .= ' dropdown';

            if ( in_array( 'current-menu-item', $classes ) )
                $class_names .= ' active';

            $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';

            $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
            $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';

            $output .= $indent . '<li' . $id . $value . $class_names .'>';

            $atts = array();
            $atts['title']  = ! empty( $item->title )   ? $item->title  : '';
            $atts['target'] = ! empty( $item->target )  ? $item->target : '';
            $atts['rel']    = ! empty( $item->xfn )     ? $item->xfn    : '';

            // If item has_children add atts to a.
            if ( $args->has_children && $depth === 0 ) {
                $atts['href']           = '#';
                $atts['data-toggle']    = 'dropdown';
                $atts['class']          = 'dropdown-toggle';
                $atts['aria-haspopup']  = 'true';
//                $atts['data-toggle'] = 'elementscroll';
            } else {
                $atts['href'] = ! empty( $item->url ) ? $item->url : '';
            }

            $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );

            $attributes = '';
            foreach ( $atts as $attr => $value ) {
                if ( ! empty( $value ) ) {
                    $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
                    $attributes .= ' ' . $attr . '="' . $value . '"';
                }
            }

            $item_output = $args->before;

链接到wp_bootstrap_navwalker

0 个答案:

没有答案