kerkness / kohana-for-wordpress

Plugin for running the Kohana 3.0 framework inside of Wordpress
http://kerkness.ca
26 stars 6 forks source link

Idea: Allow user to specify WP template for use with all Kohana requests #3

Closed mclin closed 14 years ago

mclin commented 14 years ago

I found it difficult to get Wordpress to render Kohana requests with the right template. I added a filter so that, for Kohana requests, it always uses the same page template.

add_filter('page_template', kohana_page_template_filter);

function is_kohana_request()
{
    global $wp;
    return ($wp->kohana->request != null) ? true : false;
}

function kohana_page_template_filter($template) {
    if (is_kohana_request()) {
        return locate_template(array('kohana.php'));
    }
    return $template;
}

For this code, you have to have a kohana.php template in your theme. Mine's pretty basic, but it would depend on your theme. It might be useful to be able to select a kohana page template from the WP admin.

<?php
/*
Template Name: Kohana   
*/
?>
<?php get_header(); ?>
<div id="content" class="with-sidebar">
    <div id="main-content" class="single-post">
        <div id="main-content-inner">
            <?php echo apply_filters('the_content', $post->post_content); ?>
        </div>
    </div>
</div> <!-- end main-content -->
<?php get_footer(); ?>
kerkness commented 14 years ago

If you have time, do this in your fork and send me a pull request.. I'm a little swamped but think it's a good idea

kerkness commented 14 years ago

Fixed by b296687107d1eafe06f3c7904b0212ee96c06fc4