Wordpress:仅在特定页面上显示菜单

时间:2016-04-12 15:08:19

标签: php wordpress menu

我想只在特定页面上显示菜单 - > "投资组合",以及在其他页面上浏览"主要"菜单应该是可见的。在"投资组合" -page上应该隐藏"主要" -menu。

这就是我所拥有的,但它不起作用:它给了我一个HTTP ERROR 500.

<?php if ( is_page('Portfolio') ) : ?>
        <nav id="site-navigation" class="main-navigation" role="navigation">
            <?php wp_nav_menu( array( 'theme_location' => 'portfolio', 'menu_id' => 'portfolio-menu' ) ); ?>
        </nav>
<?php endif; ?>

<?php else : ?>
        <nav id="site-navigation" class="main-navigation" role="navigation">
            <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_id' => 'primary-menu' ) ); ?>
        </nav>
<?php endif; ?>

2 个答案:

答案 0 :(得分:0)

如果您正在使用&#34; ELSE&#34;然后删除

<?php endif; ?>

答案 1 :(得分:0)

试试这个......

<?php
global $post;
$post_title = isset($post->post_title) ? $post->post_title : null;
?>

<?php if ( $post_title == 'Portfolio') : ?>
        <nav id="site-navigation" class="main-navigation" role="navigation">
            <?php wp_nav_menu( array( 'theme_location' => 'portfolio', 'menu_id' => 'portfolio-menu' ) ); ?>
        </nav>
<?php else : ?>
        <nav id="site-navigation" class="main-navigation" role="navigation">
            <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_id' => 'primary-menu' ) ); ?>
        </nav>
<?php endif; ?>