Skip to main content
Code Review

Return to Question

Rollback to Revision 2
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
 while ( $my_query->have_posts() ) : $my_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
 while ( $second_query->have_posts() ) : $second_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
 while ( $my_query->have_posts() ) : $my_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
 while ( $second_query->have_posts() ) : $second_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
 while ( $my_query->have_posts() ) : $my_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
 while ( $second_query->have_posts() ) : $second_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
Post Reopened by Malachi, Community Bot, TheCoffeeCup, 200_success
removed commented code.
Source Link
alexwc_
  • 249
  • 3
  • 12

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
 while ( $my_query->have_posts() ) : $my_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
 while ( $second_query->have_posts() ) : $second_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
 while ( $my_query->have_posts() ) : $my_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
 while ( $second_query->have_posts() ) : $second_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
 while ( $my_query->have_posts() ) : $my_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
 while ( $second_query->have_posts() ) : $second_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
Post Closed as "Not suitable for this site" by 200_success
deleted 156 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

WordPress: Multiple Loops - Best practice?multiple loops

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
 while ( $my_query->have_posts() ) : $my_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
 while ( $second_query->have_posts() ) : $second_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>

<?php endwhile; ?>

WordPress: Multiple Loops - Best practice?

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
 while ( $my_query->have_posts() ) : $my_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
 while ( $second_query->have_posts() ) : $second_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>

<?php endwhile; ?>

WordPress: multiple loops

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff.

<?php $my_query = new WP_Query( 'category_name=news&posts_per_page=3' );
 while ( $my_query->have_posts() ) : $my_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php $second_query = new WP_Query( 'category_name=reviews&posts_per_page=4' );
 while ( $second_query->have_posts() ) : $second_query->the_post();
 $do_not_duplicate[] = $post->ID; ?>
 <!-- Do stuff... -->
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
Source Link
alexwc_
  • 249
  • 3
  • 12
Loading
lang-php

AltStyle によって変換されたページ (->オリジナル) /