Skip to content

Instantly share code, notes, and snippets.

@jamesmorrison
Created August 11, 2012 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmorrison/3325984 to your computer and use it in GitHub Desktop.
Save jamesmorrison/3325984 to your computer and use it in GitHub Desktop.
Custom WordPress Loop
<?php
$custom_args = array(
// Declare your parameters. For example:
'post_type' => 'post',
'posts_per_page' => '4',
'orderby' => 'date',
'order' => 'DESC'
);
global $more; // Declare global $more (before the loop).
$custom_loop = new WP_Query($custom_args);
if ( $custom_loop->have_posts() ) : while ( $custom_loop->have_posts() ) : $custom_loop->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php
$more = 0; // Set (inside the loop) to display content above the more tag.
the_content("Continue Reading…");
?>
</article>
<?php
}
endwhile;
endif;
// reset the query
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment