wordpress is_home() || is_index() possible?

前端 未结 3 1753
礼貌的吻别
礼貌的吻别 2021-02-06 08:33

I have a test in my header.php to see whether we are at home to display a hero or not.


  
相关标签:
3条回答
  • 2021-02-06 09:25

    Try out is_front_page() from the Wordpress conditional tags list.

    It is true when you are on the "Front Page" of your wordpress installation, which is:

    • The posts page if you have set your front page to your blog/posts
    • The page you have designated as your front page, if you are using a page instead of your posts
    0 讨论(0)
  • 2021-02-06 09:29

    Try:

    <?php if ( ( is_home() || is_front_page() ) && have_posts() ) : ?>
      <div id="hero" class="inner clearfix">
        ...
      </div>
    <?php endif ?>
    

    If it still doesn't work, try adding the following just before the if statement:

    <?php wp_reset_query(); ?>
    
    0 讨论(0)
  • 2021-02-06 09:35

    Try is_front_page()

    <?php if ( is_home() || is_front_page() ) : ?>
      <div id="hero" class="inner clearfix">
        ...
      </div>
    <?php endif ?>
    

    That should return true if you are on the absolute root of site.

    0 讨论(0)
提交回复
热议问题