Skip to content

Instantly share code, notes, and snippets.

@jasondevine
Last active February 21, 2021 00:44
Show Gist options
  • Save jasondevine/1d9c9c9bd5c4cbdb58ebb7fc10e4a19a to your computer and use it in GitHub Desktop.
Save jasondevine/1d9c9c9bd5c4cbdb58ebb7fc10e4a19a to your computer and use it in GitHub Desktop.
Here's a basic skeleton for a loop called using the WP_Query class. You could use this to display a secondary loop on the homepage, for example, a block featuring specific categories.
<?php
$args = array(
// arguments for your query
);
// the query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post() ;
// contents of the Loop go here
endwhile; endif;
/* Restore original Post Data */
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment