stuart-d
1/31/2013 - 8:23 PM

gistfile1.txt

//Template fallback
//add_action("template_redirect", 'wpbaker_theme_redirect');
function wpbaker_theme_redirect() {
    global $wp;
    $plugindir = dirname( __FILE__ );

    // Load main portfolio template
    if ( is_page('portfolio') == true ) {
        $templatefilename = 'template-portfolio.php';
        if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
            $return_template = TEMPLATEPATH . '/' . $templatefilename;
        } else {
            $return_template = $plugindir . '/templates/' . $templatefilename;
        }
        do_theme_redirect($return_template);

    // Single Portfolio Page Template
    } elseif ( is_single() && $wp->query_vars["post_type"] == 'portfolio') {
        $templatefilename = 'single-portfolio.php';
        if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
            $return_template = TEMPLATEPATH . '/' . $templatefilename;
        } else {
            $return_template = $plugindir . '/templates/' . $templatefilename;
        }
        do_theme_redirect($return_template);

    } 
}

/**
 * Function: do_theme_redirect()
 * @since WPBaker QuickSand Portfolio 1.0 
 */

function do_theme_redirect($url) {
    global $post, $wp_query;
    if (have_posts()) {
        include($url);
        die();
    } else {
        $wp_query->is_404 = true;
    }
} // function: do_theme_redirect() END