[英]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.