How to create pages outside of the WordPress installation, that use WordPress themes

This is a quick guide on how to get  a file anywhere in your webhost’s file tree to serve its content as if it was part of WordPress – this can be useful if you already have a site that you only want to use WordPress for part of, or if you have WordPress that is installed in a subdirectory separate from the rest of your site, but you want to “export” a bit of it elsewhere.

Something along the lines of the following should do the job:

<?php include("wp/wp-load.php"); // include the wordpress engine ?>
<?php get_header(); // header file ?>
<?php get_sidebar("barebones"); // custom sidebar template file - hides the menu etc ?>
<div id="content" style="margin-top: 60px;">
	<?php $page=get_page_by_title("Seb Maynard"); // get the page we'd like to display ?>
	<h2><?php echo $page->post_title; ?></h2>
			// echo the content, as if we were inside the wordpress loop
			echo apply_filters("the_content", $page->post_content);
<?php get_footer(); ?>

Not too complicated, and this can be in any folder, regardless of where WordPress is installed to (just change the wp/wp_load.php path on the first line)






Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.