Multiple loops on homepage – is this efficient?
Question
I’m using underscores to create a new wordpress theme. As a mainly front end dev I’m a bit confused when it comes to the wordpress loop.
What I’m trying to achieve:
- Grid of 3 recent posts excluding category 200
- Grid of 3 recent posts from category 200 and excluding every other cat
- Grid of 12 posts starting from post 4 and excluding category 200
My loop:
<?php query_posts('cat=-200&posts_per_page=3'); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content-top'); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
<?php query_posts('cat=200&posts_per_page=2&offset=1'); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content-middle'); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
<?php query_posts('cat=-200&posts_per_page=12&offset=3'); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content-bottom'); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); reset_query();?>
<?php endif; ?>
Each of the template parts contain the excerpts, styling in cards etc
Is my way of displaying this on the homepage efficient or is there a better way to do this?
Thanks
0
loop
3 years
2019-10-30T15:28:47-05:00
2019-10-30T15:28:47-05:00 0 Answers
67 views
0
Leave an answer