Pulling posts from outside wordpress (in the right way!)

/ Published in: PHP
Save to your folder(s)

Pulling posts from outside wordpress (in the right way!) as a response for this snippet: http://snipplr.com/view/39523/pulling--posts-from-outside-wordpress/

Copy this code and paste it in your HTML
  1. <?php
  2. include('wp-load.php'); // it is neccesary to include wp-load.php, cause it's the only why to use Wordpress API outside of Wordpress
  3. // pay atention on the include path if you want to work :-)
  5. echo '<h3>Recent Blog Post</h3>';
  6. echo '<ul>';
  7. $number = 3; // number of recent posts that you want to display
  8. $recent_posts = wp_get_recent_posts($number); // this function will display recent posts, order by ID DESC
  9. foreach($recent_posts as $post){
  10. echo '<li><a href="'.get_permalink($post["ID"]).'">'.$post["post_title"].'</a></li>';
  11. }
  12. echo '</ul>';
  13. ?>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.