I have a commercial site (php), and have a WordPress blog in a subdirectory. I need to display latest posts at homepage which is out of WordPress :/
site:
http://www.blabla.com
blog:
http://www.blabla.com/blog/
So I need to display posts at www.blabla.com/index.php. How can I access WordPress functionality?
Thanks a lot! appreciate!
The easiest way is to consume your WordPress RSS feed.
Download it using
file_get_contents()
or cURL for more control.Parse it with simpleXML and output it.
You’ll probably want to cache it somewhere… you could use APC user functions or PEAR::Cache_Lite.
Edit: the code would look something like this (you’d want more error checking and stuff – this is just to get you started):
Using WordPress best practices, you shouldn’t be loading wp-blog-header.php, but rather wp-load.php, as it was specifically created for this purpose.
After this, use either the WP_Query object or get_posts(). An example of how to use WP_Query is available on The Loop page on the WordPress codex. Although using either of these doesn’t matter if you use them from outside WordPress, there’s less chance of something interfering, such as GET parameters.
For example, using WP_Query:
Or, using get_posts():
Hope this helps! 🙂
hey just found a solution online;
http://www.corvidworks.com/articles/wordpress-content-on-other-pages
works great!
I guess the easiest solution is to take posts directly from database.