Wordpress functions in other pages

by Kevin on October 19, 2008
in Journal

I have rediscovered a cool thing that can be done with Wordpress involving static pages. I run my site with a static index.php as the front page. It would be a massive pain in the ass to re-theme it every time I changed my Wordpress theme, along with any other pages I make. I remembered something in the documentation about adding a line of code to your php files and being able to access all the functions available in Wordpress and went looking, unsuccessfully.

I then remembered that the index.php file of a Wordpress install contains something like what I was looking for. I copied it (require(‘./path/to/wp-blog-header.php’) ) into the front page along with the functions to display the header, sidebar and footer (get_header(), get_sidebar() and get_footer() respectively) and found that it worked.

Full code for this is below (assumes that your wordpress install is in /wordpress and your page is in the root of your site)


<?php require('./wordpress/wp-blog-header.php'); ?>
<?php get_header(); ?>
<div id="container">
<div id="content">
<!--your stuff goes here-->
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</div>
</body>
</html>

Comments are closed.