It is possible to use CodeIgniter in conjunction with WordPress. This article details how to integrate CodeIgniter with WordPress, including an important a caveat involving 404 headers and its workaround.
Update 12/08/2011
A Github repos of recent versions of WordPress with these changes can be found here
Original Article
It is possible to use CodeIgniter in conjunction with WordPress. In fact, we do this on a regular basis! To do this you simply need to include the following in your site’s index.php file (that is, the CodeIgniter index.php in your document root), preferably at the top:
if (is_dir($_SERVER['DOCUMENT_ROOT'] . "/wordpress")) { require $_SERVER['DOCUMENT_ROOT'] . "/wordpress/wp-blog-header.php"; }
Once this has been included all of the usual WordPress template tags and other functions are available to you. You can make the post object available within your loops by declaring it global (global $post), and with this configuration the WordPress template you define for a particular page is irrelevant, as is its theme – this is controlled by WordPress. In essence, this allows you to utilize the WordPress dashboard and all of the WP metadata (tags, custom fields, etc.) and functions available to you within your themes while having your site controlled by CodeIgniter, making heavy use of the query_posts() WordPress function to call upon the content you wish to display.
The one caveat is if you have PHP’s output_buffering enabled, this will allow WordPress to send 404 headers when it thinks that your page does not exist, thereby getting Apache to log this request as a 404. The fix is either to create a dummy WordPress page that corresponds with the URL you are accessing (even if this page is blank, it doesn’t matter, CodeIgniter is driving the site and not WordPress), or else rewrite $_SERVER['REQUEST_URI'] within your theme’s functions.php to match a URL that WordPress considers valid.
Edit: we’ve up with another alternative… The following change to WordPress in: wp-includes/functions.php:
add the following to the top of the status_header function:
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/system")) {
// CodeIgniter site, WordPress should not set headers
return;
}
Pingback: Success! | Anthony Morelle's Portfolio Blog
Pingback: Portfolio Site Codeigniter + Wordpress hybrid | Anthony Morelle's Portfolio Blog