Run a Loop Outside of WordPress

Avatar of Chris Coyier
Chris Coyier on

Include Basic WordPress Functions

<?php
  // Include WordPress
  define('WP_USE_THEMES', false);
  require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
  query_posts('showposts=1');
?>

Run Loop

<?php while (have_posts()): the_post(); ?>
   <h2><?php the_title(); ?></h2>
   <?php the_excerpt(); ?>
   <p><a href="<?php the_permalink(); ?>" class="red">Read more...</a></p>
<?php endwhile; ?>

This can be used on any PHP file even OUTSIDE your WordPress installation.