Link to home
Start Free TrialLog in
Avatar of logicjb
logicjb

asked on

Show latest WordPress blog posts on homepage

Hi

I have recently installed a WordPress blog, and I would like to show the latest 4/5 posts on my homepage (outside of the blog) is there any easy way in PHP I can fetch the latest posts?

Thanks

John

Avatar of Joe Wu
Joe Wu
Flag of Australia image

Avatar of logicjb
logicjb

ASKER

Thanks, but this code only works from within wordpress. I need an external solution to call the latest posts (same server)
ASKER CERTIFIED SOLUTION
Avatar of simonkin
simonkin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of logicjb

ASKER

excellent, thanks
I know this question has been closed for a year so this is as an FYI for anyone else working on this. I wanted to include the latest posts on my home page (which happened to not be in wordpress). DO NOT RETRIEVE THIS KIND OF INFO DIRECTLY FROM THE WORDPRESS DATABASE.

A much better and easier method is to include the "wp-blog-header.php" file.

This would allow you to use Wordpress function calls on your PHP page. To figure out the correct wordpress function calls look at your theme editor pages. For example if I wanted to show recent posts, I look at my sidebar.php in the theme editor and grab out the section that displays recent posts.

Retrieving directly from the wordpress database is NOT recommended. It is not very upgrade friendly. The best method is to use the methods wordpress supplies to retrieve its information, so that as it increases in versions, everything is compliant.
<?php 
require('blog/wp-blog-header.php'); 
?>
<li><h1>Recent Posts</h1><ul><?php wp_get_archives('type=postbypost&limit=5')?></ul></li>

Open in new window