wordpress is_home()|| is_index()可能吗?

Ste*_*fan 7 php wordpress

我在我的header.php中有一个测试,看看我们是否在家里展示英雄.

<?php if ( is_home() && have_posts() ) : ?>
  <div id="hero" class="inner clearfix">
    ...
  </div>
<?php endif ?>
Run Code Online (Sandbox Code Playgroud)

但是当用户登陆index.php时,英雄没有被显示.显然没有is_index()条件,有没有人知道如何测试它的主页或索引?

bre*_*njt 19

尝试 is_front_page()

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

如果你是站点的绝对根,那应该返回true.