doure8758
2016-11-23 06:25
浏览 107
已采纳

在WordPress网站的特定页面上隐藏汉堡菜单

TheHamburgerCollection.com

My hamburger menu is working correctly on all other pages - I just don't want it to display on the home page, where it's currently visible at 768px and below.

footer.php is where the menu is located:

<div class="mobile-nav">
    <div class="menu-btn" id="menu-btn">
        <div></div>
        <span></span>
        <span></span>
        <span></span>
    </div>

    <div class="responsive-menu">
    <?php
        if ( ! is_front_page() && ! is_home() ) {
        wp_nav_menu();  
        } 
    ?>
    </div>
</div>

You can see that I've told it not to display the nav menu on the front page (which is also the home page), and it's doing this correctly - but how do I do the same thing to the hamburger menu?

I followed the instructions in this tutorial to create my hamburger menu. If I try to copy the PHP if statement that's telling the browser to display the Nav Menu on all other pages except for the Front Page / Home Page and then paste it just before the div with class and id "menu-btn", I get a syntax error:

<div class="mobile-nav">
    <?php if ( ! is_front_page() && ! is_home() ) {
        <div class="menu-btn" id="menu-btn">
            <div></div>
            <span></span>
            <span></span>
            <span></span>
        </div>
    } 
    ?>

    <div class="responsive-menu">
    <?php
        if ( ! is_front_page() && ! is_home() ) {
        wp_nav_menu();  
    } 
    ?>
    </div>
</div>

I'm not sure if there's a way to hide the hamburger menu on a specific page with CSS, or, if I do need to use PHP or JS, where should I place the function / what function should I use?

Thank you!

图片转代码服务由CSDN问答提供 功能建议

TheHamburgerCollection.com

我的汉堡菜单在所有其他页面上都能正常工作 - 我只是不希望它显示在主页上,目前它在768px及以下可见。< /p>

footer.php是菜单所在的位置:

 &lt; div class =“mobile-nav”&gt; 
&lt;  div class =“menu-btn”id =“menu-btn”&gt; 
&lt; div&gt;&lt; / div&gt; 
&lt; span&gt;&lt; / span&gt; 
&lt; span&gt;&lt; / span&gt;  
&lt; span&gt;&lt; / span&gt; 
&lt; / div&gt; 
 
&lt; div class =“responsive-menu”&gt; 
&lt;?php 
 if(!is_front_page()&amp;  &amp;!is_home()){
 wp_nav_menu();  
} 
?&gt; 
&lt; / div&gt; 
&lt; / div&gt; 
   
 
 

您可以看到我告诉它不要显示 首页上的导航菜单(也是主页)正确执行此操作 - 但我如何对汉堡菜单做同样的事情?

我按照说明进行操作 在本教程中创建我的汉堡包 菜单。 如果我尝试复制PHP if语句,告诉浏览器在除Front Page / Home Page之外的所有其他页面上显示Nav Menu,然后将它粘贴到div之前,并使用class和id“menu-btn”,我得到 语法错误:

 &lt; div class =“mobile-nav”&gt; 
&lt;?php if(!is_front_page()&amp;&amp;!is_home()  ){
&lt; div class =“menu-btn”id =“menu-btn”&gt; 
&lt; div&gt;&lt; / div&gt; 
&lt; span&gt;&lt; / span&gt; 
&lt; span&gt;  ;&lt; / span&gt; 
&lt; span&gt;&lt; / span&gt; 
&lt; / div&gt; 
} 
?&gt; 
 
&lt; div class =“responsive-menu”&gt; 
  &lt;?php 
 if(!is_front_page()&amp;&amp;!is_home()){
 wp_nav_menu();  
} 
?&gt; 
&lt; / div&gt; 
&lt; / div&gt; 
   
 
 

我不确定是否有办法隐藏 使用CSS在特定页面上的汉堡菜单,或者,如果我确实需要使用PHP或JS,我应该在哪里放置函数/我应该使用什么函数?

谢谢!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongpo5264 2016-11-23 06:32
    已采纳

    You must close php code section before you print HTML code.

    <div class="mobile-nav">
        <?php if ( ! is_front_page() && ! is_home() ) : ?>
            <div class="menu-btn" id="menu-btn">
                <div></div>
                <span></span>
                <span></span>
                <span></span>
            </div>
        <?php endif; ?> 
    
        <div class="responsive-menu">
        <?php
            if ( ! is_front_page() && ! is_home() ) {
            wp_nav_menu();  
        } 
        ?>
        </div>
    </div>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duan1982453 2016-11-23 06:37

    You are mixing the HTML with your PHP.

    Try this:

    <?php if ( ! is_front_page() && ! is_home() ) { ?>
        <div class="menu-btn" id="menu-btn">
            <div></div>
            <span></span>
            <span></span>
            <span></span>
        </div>
    <?php } ?>
    

    Explanation:

    As you can see you have the <div>...</div> inside of your PHP. You need to close first your php-section, then post your html, and then you have to end your if.

    You just need a ?> after your if(...) {

    Hope this helps.

    评论
    解决 无用
    打赏 举报
  • duanqi6274 2016-11-23 21:18

    You can do like that:

     <?php if ( ! is_front_page() && ! is_home() ) {
    <div class="mobile-nav">
            <div class="menu-btn" id="menu-btn">
                <div></div>
                <span></span>
                <span></span>
                <span></span>
            </div>
    
    
        <div class="responsive-menu">
        <?php
            wp_nav_menu();  
        ?>
        </div>
    </div>
     } 
     ?>
    
    评论
    解决 无用
    打赏 举报