简体   繁体   English

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

[英]replace navigation menu with custom div (wordpress)

How can I replace the menu in my wordpress theme with a different div - but only on a certain page of my site? 如何用不同的div替换wordpress主题中的菜单-但只能在网站的特定页面上?

Here's what it says in themes.php 这是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>

I need something to say instead something like: 我需要说些类似的话:

<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>

Thanks in advance!! 提前致谢!!

This should get the job done: 这应该完成工作:

<?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>

Fixed a small issue with the php tags 修复了php标签的一个小问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM