Skip to content

Instantly share code, notes, and snippets.

@LaminSanneh
Created July 23, 2013 08:49
Show Gist options
  • Save LaminSanneh/6060912 to your computer and use it in GitHub Desktop.
Save LaminSanneh/6060912 to your computer and use it in GitHub Desktop.
Wordpress : Loop WpQuery
<?php
$first_query = new WP_Query('cat=7&showposts=3');
while($first_query->have_posts()) : $first_query->the_post();
the_excerpt();
endwhile;
//Add next and previous links after query
next_posts_link('&laquo; Older Entries');
previous_posts_link('Newer Entries &raquo;');
//reset the query so you can get origin query
wp_reset_postdata();
?>
//Stuff to help with options
$custom_query = new WP_Query('cat=-7,-8,-9'); // exclude any categories
$custom_query = new WP_Query('posts_per_page=3'); // limit number of posts
$custom_query = new WP_Query('order=ASC'); // reverse the post order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment