I now need to make a Kohana 3 site have a WordPress blog.
I’ve seen Kerkness’ Kohana For WordPress, but it seems to be the opposite of what I want.
Here are the options I have thought of
- Style a template to look exactly like the Kohana site (time consuming, non DRY and may not work)
- Include the blog within an
iframe
(ugly as all hell) - cURL the WordPress pages in. This of course means I will need to create layers between comment posting, etc, which sounds like too much work.
Is there any way I can include a WordPress blog within an existing Kohana application? Do you have any suggestions?
I found this post detailing the Kohana for WordPress plugin, but I am still confused as to how it works.
Does it mean from within WordPress, I can call a Kohana controller? Is this useful to me in my situation?
Oh, I did this a long time ago (actually towards the end of last year).
Assumptions
Renaming
First, you need to rename the
__()
function in Kohana. Say, you rename it to__t()
. You’d need to replace it everywhere it appears, which if you use an editor like Netbeans that can find usages of a function or method is pretty easy.Hierarchy
The next decision you need to make is whether you want to load WordPress inside Kohana or Kohana inside WordPress. I prefer the latter, which I’m documenting below. I could document the latter if you’d prefer to go that route.
I put the kohana directory in my theme directory.
In your functions.php file of your theme, simply
include TEMPLATEPATH . '/kohana/index.php';
Kohana Configuration
Your Kohana’s index.php file also needs some work. Remove the lines that look for install.php as they will load
ABSPATH . WPINC . 'install.php'
instead and display an error message in your wordpress admin. You also need to change the error_reporting as at the moment WordPress fails E_STRICT.You will very likely need to remove the last few lines of your bootstrap (in Kohana) that process the request, and change your init:
In either your WordPress functions.php file or in your bootstrap, add these lines:
where Application is a class of your choosing.
My code for the Application class (without the class definition) is:
which lets WordPress do it’s redirect for any page that may have moved e.g. /about/calendar to /calendar as long as you don’t have an about controller and calendar action defined.
So there you have it. Any urls not defined within WordPress will fall to your defined controller (or use your theme’s 404 template).
Additional
This isn’t required, but you could put your theme’s header.php under your kohana views folder (application or in a module) and from any of your theme files
You could do the same thing with your footer (or any other files for that matter). In your header.php, you could also do this:
That way you could in your controller
To keep urls consistent, you may have to take off the / from the end of WordPress permalinks so /%year%/%monthnum%/%day%/%postname%/ becomes /%year%/%monthnum%/%day%/%postname%, etc
Please let me know if you need any more help integrating WordPress and Kohana.
I’ve actually used wordpress for the CMS of a code igniter site. This is the method i used to pull page content, not blog content, but maybe you can change it up a little to fit your needs.
In my front controller I added the wordpress header file
This gives you access to the 2 functions you’ll need
To get page data
If you get this error:
You have to do it like this
because of a bug in certain versions of php
Then in the view
Hope this helps
EDIT
I installed wordpress at /blog in the filesystem. So wordpress actually runs as a blog normally. I just use this method to grab the pages
This is going to be extremely difficult, because of the way WordPress works. Specifically, it uses global variables all over the place, and because Kohana is scoped, you will not be able to access those variables.
Long story short: what you want is nearly impossible. However, if you get it working (without hacking WP), I would be really interested to see how you did it.
See here: http://www.intuitivity.org/archives/8
I figured it out yesterday 🙂
Another solution is to keep both WordPress and Kohana installations completely separate. Then you create a custom WordPress theme that will pull the header and footer from Kohana (you can create a Kohana controller for that).
Once you have the header and footer in, the blog looks integrated to your website even though it’s still a completely separate installation. The advantage is that there’s nothing to hack to either WordPress or Kohana to get it working.
There’s some more details about this method in this blog post: Integrating WordPress into a Kohana application
I always thought this would be relatively easy. That is, to use WordPress as your site’s back-end (for the blog part, at least) and use Kohana for serving up posts and pages. If I’m not mistaking, all you would need to do is set up your models (post, comment, page) to gather their data from the WordPress database (with or without ORM) instead of a new one.