用自定义div替换导航菜单(wordpress)

时间:2013-07-29 00:38:16

标签: php wordpress menu

如何将wordpress主题中的菜单替换为另一个div - 但仅限于我网站的某个页面?

这是在themes.php

中所说的内容
<div class="frame">

<?php wp_nav_menu( array( 'theme_location' => 'menu-main','sort_column' => 'menu_order', 'menu_id' => 'main-nav-menu',  'fallback_cb' => false ) ); ?>

</div>

我需要说些什么来代替:

<div class="frame">

//if the page id=1545, then show this div:
<div id="my-new-div">Slogan goes here</div>

//else
<?php wp_nav_menu( array( 'theme_location' => 'menu-main','sort_column' => 'menu_order', 'menu_id' => 'main-nav-menu',  'fallback_cb' => false ) ); ?>

</div>

提前致谢!!

1 个答案:

答案 0 :(得分:0)

这应该完成工作:

<?php $page_object = get_queried_object();
$page_id     = get_queried_object_id(); ?>

<div class="frame">

<?php if ($page_id == 1545): ?>

    <div id="my-new-div">Slogan goes here</div>

<?php else: ?>

    <?php wp_nav_menu( array( 'theme_location' => 'menu-main','sort_column' => 'menu_order', 'menu_id' => 'main-nav-menu',  'fallback_cb' => false ) ); ?>

<?php endif; ?>


</div>

修正了php标签的一个小问题