在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"代码包装条目内容部分:
<?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"的说明。
有什么想法吗?谢谢你事先的帮助。
在WordPress管理中创建页面时,您给首页起的名字是什么?
尝试:
if ( is_page( 'page-name-here' ) ) {
// your content
}
合并主页和首页条件,如下所示:
if (is_home() || is_front_page()) {
// your content
}