我有一个快捷码,可以使用wp_nav_menu
就像这样
if ( ! function_exists( \'foundationPress_main_nav\' ) ) {
function foundationPress_main_nav() {
wp_nav_menu(array(
\'container\' => false, // remove nav container
\'container_class\' => \'\', // class of container
\'menu\' => \'\', // menu name
\'menu_class\' => \'\', // adding custom nav class
\'theme_location\' => \'main-nav\', // where it\'s located in the theme
\'before\' => \'\', // before each link <a>
\'after\' => \'\', // after each link </a>
\'echo\' => true,
\'link_before\' => \'\', // before each link text
\'link_after\' => \'\', // after each link text
\'depth\' => 2, // limit the depth of the nav
\'fallback_cb\' => false, // fallback function (see below)
// \'walker\' => new FoundationPress_top_bar_walker()
));
}
}
菜单已注册
register_nav_menus(array(\'main-nav\' => \'Main Navigation\',));
并在Wordpress管理员中设置。
这就是它表现奇怪的地方:它没有在我呼应它的元素中呈现。例如,如果短代码中的代码类似于:
<nav>
<?php foundationPress_main_nav(); ?>
</nav>
而不是出现在
<nav>
元素(位于页面中部,折叠下方)它出现在页面顶部,是嵌套在中的第一个元素
div.entry-content
.
Any ideas why it\'s sort of hooking to the top of the page this way instead of rendering within the element it\'s actually nested in?
(我正在使用FoundationPress框架构建主题,之前我制作了很多菜单,不确定是否遗漏了一些明显的内容)
要了解更多详细信息,请查看完整的短代码,尽管只有最后几行与此问题相关:
function rvr_cards_carousel( $atts ) {
$atts = shortcode_atts(
array(
\'background\' => \'\',
\'load\' => \'10\',
), $atts, \'rvr_cards\' );
$args = array(
\'post_type\' => \'cards\',
\'posts_per_page\' => $atts[\'load\'],
\'order\' => \'ASC\',
);
$cards_query = new WP_Query( $args );
$output = \'\';
if( $cards_query->have_posts() ) :
if( ! empty( $atts[\'background\'] ) ) {
$output .= \'<div class="cards-carousel-container row full-width" style="background: url(\'.$atts["background"].\') no-repeat left top / cover;">\';
} else {
$output .= \'<div class="cards-carousel-container row full-width">\';
}
$output .= \'<ul class="cards-carousel" data-equalizer>\';
while( $cards_query->have_posts() ) : $cards_query->the_post();
$output .= \'<li>\';
$output .= \'<div class="inner" data-equalizer-watch>\';
$output .= get_the_content();
$output .= \'<div class="card-divider"></div>\';
$output .= \'<h6 class="card-author">\'.get_the_title().\'</h6>\';
$output .= \'<div class="card-symbol"></div>\';
$output .= \'</div>\';
$output .= \'</li>\';
endwhile;
endif;
wp_reset_postdata();
$cardnav = "enabled";
$output .= \'</ul>\';
if ($cardnav = "enabled") {
$output .= \'<div class="four columns"></div>\';
$output .= \'<nav class="contain-to-grid eight columns primary-nav" id="home-card-nav">\';
$output .= foundationPress_main_nav();
$output .= \'<div id="card-nav-overflow"></div></nav>\';
}
$output .= \'</div>\';
echo $output;
}
add_shortcode( \'rvr_cards\', \'rvr_cards_carousel\' );
这是一幅描述短代码的图片,菜单应该在哪里,它在哪里。您还可以
access the live page here.