HomeCoding & Programming

Display Recent Blog Posts Outside WordPress

Display Recent Blog Posts Outside WordPress
Like Tweet Pin it Share Share Email

Generally web master uses the WordPress for applying blog on their website.

 

Below is the code for the getting recent/latest post or list, can be applied to display recent posts outside anywhere in your WordPress website.

 

The key to use WordPress outside is include the wp-load.php file
Once the wp-load.php file is included, the entire wealth of WordPress functions will available for you to use.
This can be found under the root folder.

<?php

require_once 'wp-load.php';

// Recent 10 posts
 $recent_posts = wp_get_recent_posts(array('numberposts' => 10));

// Apply your design/html
 echo '<ul>';
 foreach($recent_posts as $post) {
 echo '<li><a href="', get_permalink($post['ID']), '">', $post['post_title'], '</a></li>';
 }
 echo '</ul>';

?>

If you want to pass more argument, you can do, below is the WordPress reference URL for wp_get_recent_posts function
http://codex.wordpress.org/Function_Reference/wp_get_recent_posts

 

You can also do your own custom queries with WP_Query.

 

Comments (3)

  • Good web site! I really love how it is easy on my eyes and the data are well written. I’m wondering how I might be notified when a new post has been made. I have subscribed to your RSS which must do the trick! Have a great day!

  • I just want to mention I’m newbie to blogs and actually enjoyed your web site. Probably I’m likely to bookmark your site . You really have awesome writings. Thanks a bunch for revealing your blog site.

  • I just want to say I am just beginner to weblog and actually enjoyed you’re blog site. Likely I’m likely to bookmark your blog . You actually have really good stories. Bless you for sharing with us your web site.

Comments are closed.