• Hello,
    Im using this code to load post with different template (for print version):
    in functions.php

    //add my_print to query vars
    function add_print_query_vars($vars) {
        // add my_print to the valid list of variables
        $new_vars = array('my_print');
        $vars = $new_vars + $vars;
        return $vars;
    }
    
    add_filter('query_vars', 'add_print_query_vars');
    
    add_action("template_redirect", 'my_template_redirect_2322');
    
    // Template selection
    function my_template_redirect_2322()
    {
        global $wp;
        global $wp_query;
        if (isset($wp->query_vars["my_print"]))
        {
            include(TEMPLATEPATH . '/my_print_template.php');
            die();
    
        }
    }

    in my_print_template.php

    <?php
        define('WP_USE_THEMES', false);
        echo "<h1>printer friendly version:</h1>\n";
        query_posts('p='.$_GET['pid']);
        if (have_posts()){
            while ( have_posts() ) { the_post();
                the_content();
            }
        }else{
        echo 'nothing found';
        }
    ?>

    now all I have to do is create a link with ?my_print=$post_id in my regular single loop

    Code working very good 100%

    I would like use until five templates, my_print_template.php, my_print_template2.php, my_print_template3.php, my_print_template4.php, my_print_template5.php

    How Can I do to redirect until five templates?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Load post with a different template’ is closed to new replies.