-1
我的wordpress循環出現了一些問題。 我在頭版中創建了2個循環,第一個循環僅僅是'精選'類別中的1個文章(類似於粘貼文章)。第二個循環只是正常的循環(不包括'精選'類別的1篇文章)。WordPress多個循環 - 每個帖子頁面頂部顯示的第一個循環
但問題是我的第一個循環(從特色類別開始的1個帖子)總是顯示在每個頁面的頂部,例如主頁,第二頁的帖子,第三頁的帖子。
下面是我的代碼,不知道出了什麼問題。幫助讚賞。
<?php do_action('responsive_mobile_blog_title'); ?>
<?php if (have_posts()) : ?>
<?php get_template_part('template-parts/loop-header'); ?>
<?php /* Start the Loop */ ?>
<?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<?php get_template_part('template-parts/content', get_post_format());?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
if ($post->ID == $do_not_duplicate) continue; ?>
<?php get_template_part('template-parts/content', get_post_format());?>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
<?php responsive_mobile_paging_nav(); ?>
<?php else : ?>
<?php get_template_part('template-parts/content', 'none'); ?>
<?php endif; ?>
非常感謝,夥計。我把第一個循環包裝在if(!is_paged())中,現在它效果很好。第一個循環現在只顯示在第一頁,而不是2,3,4頁的分頁。以前我直接從wordpress Codex例子修改了多個循環代碼,沒有if(!is_paged()),所以我從來沒有想過。剛開始學習修改wordpress。非常感謝。 – Fan
沒問題,如果我的文章幫助了你,請將它標記爲正確答案:) – user8753566