[英]Wordpress - Frontpage “If” within “have_posts” while loop
在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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.