Thursday Night

Paul Betts’s personal website / blog / what-have-you

Upgrading Wordpress + Using WP themes on other sites

Today after finding easy instructions on how to upgrade my Wordpress install, I set out to run the upgrade. Unfortunately, earlier I added a bunch of hacks so that I could make pages on www.paulbetts.org look like the blog pages. Of course, I didn’t write down any of these and so finding them consisted of parsing through a giant diff file to see if I recognized anything. After some work, I found the lines changed and made sure to create a patch to add the lines back in whenever I upgrade.

I then realized the following:

  1. I have a patch detailing my changes
  2. I often write or contribute to Free software

Ta-da!

Apply with patch -p1 in your htdocs directory and copy embed.php.txt to your theme directory and rename it to embed.php. Then, rename your sidebar.php to sidebar_content.php and copy sidebar.php.txt to your theme directory as sidebar.php

Basically, the idea behind this patch is that it allows you to use your Wordpress theme on other sites that aren’t managed by Wordpress. My home page isn’t a WP site, it’s just some static content but I didn’t want to have to recreate my blog theme everywhere or do some sort of tricky redirect to use WP’s Pages feature.

Here’s how I use this, I replace index.htm on www.paulbetts.org with this and rename it to index.php:

< ?php

global $embed_target;
global $embed_target_sidebar;

define(‘WP_USE_THEMES’, true);
$embed_dir = getcwd();
$embed_target = $embed_dir . "/index_content.html";
$embed_target_sidebar = $embed_dir . "/index_sidebar.php";

chdir(‘/var/www/blog/htdocs’);
require(‘./wp-blog-header.php’);

?>

Then, I created two files, index_content.html and index_sidebar.php. You can see the content file here; basically it’s just the HTML body code; the sidebar code is very similar and can be seen here.

Written by Paul Betts

November 27th, 2006 at 8:42 pm

Posted in Programming