Thursday, March 14, 2013

How to run the loop outside of WordPress

How to run the loop outside of WordPress

If you need to access your WordPress content and need to run a loop OUTSIDE of your WORDPRESS install? The following code snippet can allow you to run a WordPress loop on any PHP file, or even outside of your WordPress install.

So just paste the following code on any PHP file where you want to run your WordPress loop for accessing data. So for this you need to modify the following:

line 4: Please specify the path to your WordPress wp-blog-header.php file.
line 5: Query posts using the query_posts() function.

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

<?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; ?>

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off