Thursday, October 24, 2013

Getting Wordpress Content without Theme and Raw Data only

I have this knowledge base stashed away in blog format on a wordpress site. I would like to use the contents in a support page external to this site using EXTJS. How do I get the Wordpress Content without Theme but just the content. You would think its easy however .... so here the end result. Plop this in the root directory of the wordpress installation (where the wp-config.php resides).
<?php
# load the wp system
require ('wp-config.php');
# create the original request from the client
$url = 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
# extract the post id
$page_id = url_to_postid($url);
echo '';
# fetch post and echo it to the outputstream.
$page_data = get_post($page_id);
echo $page_data->post_content;
?>
NOTE: make sure this new file content.php has permissions 744 chmodded otherwise it won't execute So now you can do the following:
  • For formatted output: http://mywordpress.org/?p=2049
  • For unformatted output: http://mywordpress.org/content.php?p=2049

No comments:

Post a Comment