【发布时间】:2014-06-12 12:52:38
【问题描述】:
在 Wordpress 上,我有一个小块显示我网站公共页脚中的最新帖子。我希望能够只在首页显示例外情况,并在使用此通用页脚的任何其他页面上隐藏这些例外情况(仅显示帖子标题)。
这是我的工作代码:
<?php while ( have_posts() ) : the_post(); ?>
<div class="large-6 columns footer-news-title">
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<section class="entry-header">
<h5><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h5>
</section>
<section class="entry-content">
<?php the_excerpt(); ?>
</section>
</article>
</div>
<?php endwhile; ?>
我在标题中使用了“If Frontpage”循环,所以我认为应该用我之前使用的“If”代码来包装 entry-content 部分:
<?php if( is_front_page() ) : ?>
<section class="entry-content">
<?php the_excerpt(); ?>
</section>
<?php endif;?>
但是,这不起作用。当我像上面那样包装代码时,我在任何页面上都没有摘录。当我将“is_front_page”更改为“is_home”或“is_home_page”时,我会在所有页面上获得摘录。
今天早上我花了一些时间四处寻找,但我只能找到有关使用“If”语句或“While”语句的说明,但没有找到关于在 Wordpress 上的“while”中使用“If”的说明。
有什么想法吗?提前感谢您的帮助。
【问题讨论】:
-
你试过
is_home()而不是is_front_page() -
是的。这给了我每一页的摘录(我没想到)。
-
您正在编辑什么模板文件?因为你也可以通过放入正确的模板文件来控制一些,,if''。
标签: php wordpress loops if-statement while-loop