How can CodeIgniter and WordPress be integrated such that the look and feel/template of the WordPress blog is carried over to the CodeIgniter-created pages?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Here is another way to use WordPress templates in your codeigniter project. This works better for me so I wanted to share it. Tested with WordPress 3.3.1 and Codeigniter 2.1.
Directory Structure:
/ci/index.php (Top of CI Index file)
Deal with the site_url function collision by overriding the default codeigniter version. You will need to change any place you used
site_url()
in codeigniter to useci_site_url()
instead./ci/application/helpers/MY_url_helper.php
You can now use the WordPress
get_header()
and/orget_footer()
functions to draw the template in your CI project.First step is to move CodeIgniter and the WordPress files in their own directory.
After that, put the following line at the top of your CodeIgniter's
index.php
file. Change the path towp-blog-header.php
as needed to point to your WordPress's root directory.Then, you can use the following functions inside your views:
Other helper functions can also be found in WordPress's documentation which can assist you in integrating the design.
if you're planning on using the code ignitor site_url function in your code, or if you're doing a merge of an existing CI site and WP... this might be helpful:
at the top of CI index.php:
effectively this allows you to use site_url in CI, so if you've already added a ton of links and content to your project it might help you out.
I'm using Wordpress for managing articles in a custom CI e-commerce website. CI is my main site. The directory structure is the following:
I'm able to use Wordpress functions in my CI controllers without my URLs being messed up when adding the following code to the top of CI's index.php:
Works also when using CI i18n library by Jérôme Jaglale (http://jeromejaglale.com/doc/php/codeigniter_i18n).
When I included the file wp-blog-header.php in Codeigniter's index.php page, I got a problem that site_url() is defined in both codeigniter's URL helper and WordPress. I solved this using the following code:
Last line needs to be added as WordPress file was adding a HTTP response header 'HTTP/1.0 404 Page not found' to the header.
Now its fine to use WordPress functions to call in CodeIgntier.