Importing a WordPress XML File Into Your Custom CMS.
Our mission: to make yet another bridge between website planning and website running. A couple of months back we launched a new export format in Jumpchart that allows our users to swoop their project straight into the WordPress CMS. We think it works great, and we got a lot of amazing feedback from our users.
While WordPress is a widely used CMS, unfortunately we don’t use it for most of our own web projects. We have a totally custom built system that we’ve been constantly tweaking and evolving for three years to fit our exact needs — internally, we call it Haydn (after Joseph).
So how were we going to make link between Haydn and Jumpchart?
The first thought was to make a private ‘Export to Haydn’ function inside Jumpchart. It sounded logical and simple enough, but there was something even simpler. When we stopped to think about the opportunities the WordPress export format gives us, it was clear where we should head. Put simply, a WordPress export is a regular XML file with all the flexibility of XML. It’s universally simple, and it can be read and parsed by virtually any programming language.
We write PHP here at Paste, and we took advantage of the built-in DOMDocument class, which makes coding look a lot like the old-school Javascript (remember element.getElementsByTagName?). Besides being easy, the nostalgia of it all was pretty fun.
$Document = new DOMDocument();
$Document->load(‘wordpress-export.xml’); $pages = $Document->getElementsByTagName(‘item’);
foreach($pages as $page)
{
/* Convert Jumpchart/WordPress data as required by the CMS data structure */
} ?>
We wanted an import function that was specifically tailored to our needs. Figuring out what would work and what wouldn’t was the most difficult part. Once we nailed that thought process down, the rest sort of fell into place. And we can’t wait to see how it’s going to affect the efficiency of our workflow from here on out. Something we thought would be difficult and time consuming turned out to be easier than planned, and will hopefully prove more useful than we ever imagined.
After a couple of hours and a little more than 100 lines of code, we have our new Jumpchart importer inside our custom CMS. Cool, fast and fun. If you’re like us, and have a custom CMS, give writing your own importer a try. It’s easier than you think.