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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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>
http://mu.wordpress.org/forums/topic.php?id=5223&page
http://www.scriptygoddess.com/archives/2007/04/28/wordpress-make-home-page-show-latest-post-in-the-single-post-format/
hoep this answers your question.