我在我的header.php中有一个测试,看看我们是否在家里展示英雄。
<?php if ( is_home() && have_posts() ) : ?>
<div id="hero" class="inner clearfix">
...
</div>
<?php endif ?>但是当用户登陆index.php时,英雄不会出现在屏幕上。显然没有is_index()条件,有没有人知道我如何测试它是主目录还是索引?
发布于 2011-07-15 05:16:37
试试is_front_page()
<?php if ( is_home() || is_front_page() ) : ?>
<div id="hero" class="inner clearfix">
...
</div>
<?php endif ?>如果你在站点的绝对根目录上,它应该返回true。
发布于 2011-07-15 05:21:00
尝试:
<?php if ( ( is_home() || is_front_page() ) && have_posts() ) : ?>
<div id="hero" class="inner clearfix">
...
</div>
<?php endif ?>如果仍然不起作用,请尝试在if语句之前添加以下内容:
<?php wp_reset_query(); ?>发布于 2011-07-15 05:17:05
尝试从Wordpress conditional tags list中使用is_front_page()。
这是真的,当你在你的wordpress安装的“首页”,这是:
如果您已将博客/帖子的首页设置为已指定为首页的页面,如果您使用的是页面而不是您的帖子
,请使用帖子页
https://stackoverflow.com/questions/6700001
复制相似问题