Is there a way to integrate WordPress within an existing PHP Framework, CMS, and Navigation system?

WordPress itself doesn’t actually produce the complete HTML, just parts of it, and only when the theme tells it to. It leaves the header and body and such up to the theme. So if your theme didn’t output a section, then it wouldn’t be output.

While WP itself really is a full fledged CMS, you can use it as just a generator for a section as follows:

  1. Make a theme that only outputs the bits you want. A theme can be as simple as a style.css file and an index.php file with a Loop in it. See http://codex.wordpress.org/The_Loop

  2. If you examine WP’s main index.php file, you’ll see that it does nothing more than define('WP_USE_THEMES', true); and then require('./wp-blog-header.php');. So you can do the same to start up WP and produce the output.

  3. URL handling could be tricky. WordPress expects to live at some “root” URL and to handle (most) URLs underneath it. So it would need to know that root URL in the home and siteurl. Implementing it as a module, if you knew these in advance, then you could pre-define WP_HOME and WP_SITEURL before including it so as to force the issue. See, WordPress’ own .htaccess basically routes any URL that does not already exist as a file or directory on the system to the index.php. Then it does its own URL parsing after that, and it knows to subtract the root from that, more or less.

That should probably be enough to get you started at least. The trick is that if you implement it this way, it’s not going to work with just any WP theme, you’ll have to provide special “section only” themes with it. You may need custom code to disable other things as well, like sidebars, menus, anything that doesn’t fit into your design of having WP as only a partial page generator.

Leave a Comment