This is my category / archive page
i want to include a template before loop
but i cant get posts based on category, it showing latest post only on every page.
when i removed this line before the loop
<?php include( TEMPLATEPATH . '/includes/tb/hot_posts.tpl.php' ); ?>
it work smoothly, but i need this template before the loop
this is code (archive / category )
<div class="Hot_post">
<?php include( TEMPLATEPATH . '/includes/tb/hot_posts.tpl.php' ); ?>
<?php if (have_posts()) : $count = 0; ?>
and this is code from template (includes/tb/hot_posts.tpl.php)
<?php query_posts('meta_key=post_views_count&order=DESC'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
please guide me
try and add
at the end of your template.
http://codex.wordpress.org/Function_Reference/wp_reset_query
Your problem has nothing at all to do with including a template-part file (for which, by the way, you should be using
get_template_part()
orlocate_template()
), and everything to do with Doing It Wrong with respect toquery_posts()
.If you’re trying to override the main Loop query, then you need to make sure you’re doing so correctly. If you need to maintain the default query context, and append query arguments, then you have to maintain the default
$wp_query
. The easiest way to do so is as described in the Codex:To use your custom arguments, for example:
If, by chance, you’re intending to perform a secondary loop, then you don’t want to use
query_posts()
at all, but instead need to useWP_Query()
orget_posts()
.