Welcome to the BlueLayerMedia Web Development Blog
We don't just build blogs, we write them too. Take a look at what's going on and our senseless ramblings!
WordPress and CodeIgniter Integration
By: Jason Craig on Jul 22, 2011 | 5 Comments
WordPress and CodeIgniter are two of our favorite systems to work with. CodeIgniter is an absolutely fantastic framework to work with and WordPress is a great CMS out of the box.
Occasionally we are given a project which entails us integrating the two together. In one recent project, CodeIgniter was handling the front and back ends of the website and WordPress would strictly be handling the blog aspect. There were instances on the site where we wanted to include some of WordPress’ posts in a sidebar. However, simply calling WordPress’ The Loop wouldn’t work. Simply requiring the blog header file to get the Loop to pull in data didn’t work either. It simply threw the page in to an infinite loop. Changing the require to require_once didn’t help matters.
Here’s the fix:
Open up CodeIgniter’s index.php file. Scroll to the bottom of the file and you’ll see some code that looks like this:
/* * -------------------------------------------------------------------- * LOAD THE BOOTSTRAP FILE * -------------------------------------------------------------------- * * And away we go... * */ require_once BASEPATH.'core/CodeIgniter'.EXT; /* End of file index.php */
Change the file to look like this:
/* * -------------------------------------------------------------------- * LOAD THE BOOTSTRAP FILE * -------------------------------------------------------------------- * * And away we go... * */ require_once 'blog/wp-load.php'; require_once BASEPATH.'core/CodeIgniter'.EXT; /* End of file index.php */
Refresh the page you were looking on and you’ll see you’re not stuck in an infinite loop and you can begin pulling in WordPress data as well.
Related Posts:
- Adding CSS To WordPress Menu Item
- How To: Remove The WordPress Admin Bar
- How To: Reset WordPress Administrator Password via Cpanel
- How To: CSS Shorthand
- WordPress: Moving from WordPress.com to WordPress.org
Comments (5)
Frank
Posted at 9:32 pm on December 17th, 2011
Excellent, thanks very much for this. I was pulling my hair out trying to get codeigniter to pull in wordpress, and this solved it for me.
Jason Craig
Posted at 4:12 am on December 18th, 2011
You’re welcome!
Diyafury
Posted at 2:18 pm on January 10th, 2012
Hi there
I want to do exactly the same thing – I have an existing db drive site written in codeIgniter… I now need to add a WordPress blog element/s to this existing framework… eg. latest posts and the comment functionality embedded in an existing page.
Could you please advise me on what the directory structure should look like… ie. where should I install wordpress?
Jason Craig
Posted at 5:24 pm on January 10th, 2012
You can install it as you normally would in the root folder alongside the CI structure.
Peter Drinnan
Posted at 9:07 am on March 18th, 2012
Here is a quick fix for a bug you will find if using QTranslate (used for bilingual WP sites). QTranslate messes up the request_uri and can cause the CI router to fail.
$request_uri = $_SERVER['REQUEST_URI'];
require_once ‘blog/wp-load.php’;
// restore the original
$_SERVER['REQUEST_URI'] = $request_uri ;
require_once BASEPATH.’core/CodeIgniter’.EXT;
Post a Comment
Search
Categories
- Company News (19)
- General (26)
- How-To (7)
- Mobile (1)
- MySQL (1)
- Programming (20)
- Programming Tips (2)
- Projects (3)
- Prosper202 (4)
- Video Tutorials (7)
- Wordpress Plugins (15)
- WordPress Themes (1)
- WP e-commerce (4)
Popular Posts
-
WP e-commerce Google Checkout Fix
Mar 18, 2010 · No Comments
-
WP Plugin: Random Testimonials v1.1
Apr 6, 2010 · 21 Comments
-
WP e-commerce Cart Thumbnail Mod
Mar 24, 2010 · No Comments
-
How To Install Prosper202
Mar 11, 2010 · 9 Comments
Recent Comments
-
Jason Craig on WordPress: Increase Your CTR With Google Snippets!
-
Jason Craig on 1-999-910-0122 Telephone Scam
-
Craig Porter on 1-999-910-0122 Telephone Scam