我对Wordpress很陌生,尤其是在PHP编程方面。我正在使用Ciola Theme from Theme Forest. 我想实现的是在主菜单下显示一个子菜单,但仅针对特定类别。我在theme中添加了菜单core-functions.php:
add_theme_support( \'menus\' );
// registering menus
register_nav_menus(
array(
\'top\' => \'Top Navigation Menu\', // top nav
\'main\' => \'Main Navigation Menu\', // main nav in header
\'wybrzeze\' => \'Wybrzeże Navigation Menu\', // wybrzeze nav in header
\'footer\' => \'Footer Navigation Menu\', // secondary nav in footer
)
);
我的条目是wybrzeze,Wybrzeże导航菜单。
然后我编辑了header.php 文件以尝试添加主题支持者要求我填写的一些信息:
<!-- Holding main menu -->
<?php if ( has_nav_menu( \'main\' ) ) {
$cb_main_menu = wp_nav_menu(
array(
\'echo\' => FALSE,
\'container_class\' => \'cb-main-menu\',
\'theme_location\' => \'main\',
\'depth\' => 0,
\'walker\' => new CB_Walker,
\'items_wrap\' => \'<ul class="nav main-nav clearfix sf-menu">%3$s</ul>\',
));
}
?>
<!-- Holding Wybrzeze menu -->
<?php if ( has_nav_menu( \'wybrzeze\' ) ) {
$cb_main_menu = wp_nav_menu(
array(
\'echo\' => FALSE,
\'container_class\' => \'cb-main-menu\',
\'theme_location\' => \'main\',
\'depth\' => 0,
\'walker\' => new CB_Walker,
\'items_wrap\' => \'<ul class="nav main-nav clearfix sf-menu">%3$s</ul>\',
));
}
?>
如果我理解正确,这就是我必须添加子菜单的地方。在收割台的最末端。php有几个div负责显示“main”菜单:
<nav role="navigation">
<div id="cb-main-menu" class="wrap clearfix"><?php if ( has_nav_menu( \'main\' ) ) { echo $cb_main_menu; } ?> </div>
<div id="cb-main-menu-mob" class="wrap clearfix"><div id="cb-mob-dropdown-main"></div><?php if ( has_nav_menu( \'main\' ) ) { main_nav(); } ?></div>
现在,我的问题是:是否有可能实现
this picture?
有没有办法让第二行菜单只显示选定的类别?
我在考虑使用if/else PHP循环和WP引用<?php is_category( $category ); ?>
但不幸的是,我不知道如何做到这一点,我不想打破主题。。。我将非常感谢您的帮助:)
&更新;解决方案:
幸亏Bindiya Patoliya 我找到了解决方案:
<?php if(is_category(\'teatr-wybrzeze\')) {
wp_nav_menu( array(
\'container_id\' => \'cb-main-menu\',
\'container_class\' => \'wrap clearfix\',
\'theme_location\' => \'rafalmenu\',
\'depth\' => 0,
\'items_wrap\' => \'<ul class="nav main-nav clearfix sf-menu">%3$s</ul>\',
\'walker\' => new CB_Walker
) );
} ?>
现在效果很好!非常感谢!