wordpress is_home() ||is_index() 可能吗? [英] wordpress is_home() || is_index() possible?
本文介绍了wordpress is_home() ||is_index() 可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的 header.php 中有一个测试,看看我们是否在家显示英雄.
<?php if ( is_home() && have_posts() ) : ?><div id="hero" class="inner clearfix">...
<?php endif ?>
但是当用户登陆 index.php 时,英雄没有被显示.显然没有 is_index() 条件,有谁知道我如何测试它的主页或索引?
解决方案
试试 is_front_page()
<div id="hero" class="inner clearfix">...
<?php endif ?>
如果您位于站点的绝对根目录,那应该返回 true.
I have a test in my header.php to see whether we are at home to display a hero or not.
<?php if ( is_home() && have_posts() ) : ?>
<div id="hero" class="inner clearfix">
...
</div>
<?php endif ?>
But when the user lands on index.php the hero is not being shown. apparently there is no is_index() condition, does anyone know how I could test for if its home or index?
解决方案
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.
这篇关于wordpress is_home() ||is_index() 可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文