Skip to content

Instantly share code, notes, and snippets.

@michaeloeser
Created March 25, 2013 10:32
Show Gist options
  • Save michaeloeser/5236252 to your computer and use it in GitHub Desktop.
Save michaeloeser/5236252 to your computer and use it in GitHub Desktop.
WordPress Custom Loop
<?php $custom_query = new WP_Query('cat=-9'); // exclude category 9
while($custom_query->have_posts()) : $custom_query->the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>
@michaeloeser
Copy link
Author

If you want to show a specific page do something like:

   $my_query = new WP_Query('page_id=88');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment