• Resolved PoliteShrimp

    (@terminator_5505)


    I used template include filter hook to load a sing PHP file inside my theme using a URL parameter
    http://codex.wordpress.org/Plugin_API/Filter_Reference/template_include
    I added this code to the end of functions.php

    add_filter( 'template_include', 'custom_template' );
    
    function custom_template($template) {
       global $wp, $wp_query;
      if ($wp_query->query_vars['m'] === '1') {
        return TEMPLATEPATH . '/custom-template.php';
      } else {
        return $template;
      }
    }

    I can’t load the posts to the template with this code it returns blank

    <div id="content">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
              <h2 class="item"><span class="fn"><?php the_title(); ?></span></h2>
            <?php the_content(); ?>
        <?php endwhile; else: ?>
        <?php endif; ?>
    </div>

    the code render blank

    <div id="content">
    </div>

    I need to have a custom template with the URL parameter ?m=1
    I don’t want to use another parameter
    thank you.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to load posts in a single template file ?’ is closed to new replies.