Skip to content


Kohana for Wordpress RC1 Usage Examples

Now that Kohana version 3.0 has reached a release candiate version I have also moved the Kohana-For-Wordpress plugin into a RC1 status and thought it would be useful to post some usage examples. Click here to download the plugin

There are five ways which you can call a Kohana controller from wordpress

1 – Use wordpress permalinks, .htaccess and Kohana default routing

2 – Use wordpress dashboard to bind kohana controllers to wordpress pages

3 – Use a template tag to call a controller from your wordpress templates

4 – Use a shortcut tag to call a controller from within a wordpress post or page

5 – Add a KohanaWidget to your wordpress sidebar

Using Permalinks and Default Routing

Follow the Wordpress instructions to set up permalinks for your blog. I use a custom permalink structure of /%postname%/ which works well.  If you do this then you can also call any valid Kohana controller as long as the controller name does not conflict with your post name.

For example. If you have the following Kohana controller in application/classes/controller/mycontroller you’ll be able to call this controller from the url http:/myblogurl.com/mycontroller.

Important things to remember: You’re controller will be loaded as if it is the content of a wordpress page. The page content will be whatever you set as your controller response. The title of the page however is taken from the wordpress database by default.  To set the title of your page with your Kohana controller you must update the ‘title’ property of the Kohana request object as shown below

$this->request->title = “My Page Title”;

Bind a Kohana Controller to a Wordpress Page

If you go to the Settings > Kohana section of your wordpress dashboard you’ll have the ability to set some custom page routing.  Simply enter the Kohana controller ( controller/action/id )  in the appropriate input field and select a wordpress page from the dropdown menu.  You also have the option to set the desired placement of the controller’s response.

Calling a Kohana Controller from a Wordpress Template

From any wordpress template or theme file you have the option of calling a Kohana Controller using the following syntax

<?php kohana(’controller/action/id’); ?>

Using a Shortcut tag to call a Kohana Controller from a Post or Page

If you want to call a Kohana Controller directly from a Wordpress post or page just use the following syntax when editing your content

[ request controller/action/id ]

Add a KohanaWidget to your Wordpress Sidebar

From the Apperance > Widget section of your dashboard add the KohanaWidget to your sidebar and provide a title and the controller you wish to call ( example  controller/action/id )

Questions and Support

For more support and to get answers to your questions head to http://forum.kohanaphp.com

Posted in Code.


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. pavan says

    plz post me the souce code in adobe flex to implement sudoku game

  2. Kerk says

    the source isn’t open. sorry.

  3. Louis says

    Does it matter where the WP and Kohana folder are in relation to each other as long as the settings are right in the WP plugin?

    Currently my wordpress file is in the same level as the kohana applications/modules/system etc.
    Obviously this is not working somehow.

    Cheers



Some HTML is OK

or, reply to this post via trackback.



close