Skip to main content
Home / Code Snippets / WordPress / Run a Loop Outside of WordPress

Run a Loop Outside of WordPress

Include Basic WordPress Functions

  // Include WordPress
  define('WP_USE_THEMES', false);

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.

icon-link icon-logo-star icon-search icon-star