Multiple Loops not working
-
hello experts, need your helps ??
my homepage needs two loops(first loop includes posts from featured category, second loop includes just normal posts) , so i searched the codex, found the following code exactly match my needs.<?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; ?> <!-- Do stuff... --> <?php endwhile; ?> <!-- Do other stuff... --> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); if ( $post->ID == $do_not_duplicate ) continue; ?> <!-- Do stuff... --> <?php endwhile; endif; ?>
However, after i modified my theme’s loop code, the result is that “the first loop and second display fine on homepage, but when i click the second page of posts, the same posts from first loop also display on top of that. as well as the third page…”
the following is my theme’s original loop codeif ( ! defined( 'WPINC' ) ) { die; } get_header(); ?> <div id="content-blog" class="content-area"> <main id="main" class="site-main" role="main" itemprop="mainContentOfPage" itemscope="itemscope" itemtype="https://schema.org/Blog"> <?php do_action( 'responsive_mobile_blog_title' ); ?> <?php if ( have_posts() ) : ?> <?php get_template_part( 'template-parts/loop-header' ); ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php /* Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'template-parts/content', get_post_format() ); ?> <?php endwhile; ?> <?php responsive_mobile_paging_nav(); ?> <?php else : ?> <?php get_template_part( 'template-parts/content', 'none' ); ?> <?php endif; ?> </main><!-- #main --> <?php get_sidebar(); ?> </div><!-- #content-blog --> <?php get_footer(); ?>
can anyone show me the correct code of displaying these 2 loops for my theme.
Thank you so much.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Multiple Loops not working’ is closed to new replies.