Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

try and add

<?php wp_reset_query(); ?> 

at the end of your template. http://codex.wordpress.org/Function_Reference/wp_reset_query

share|improve this answer
add comment

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() or locate_template()), and everything to do with Doing It Wrong with respect to query_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:

global $wp_query;
$args = array_merge( $wp_query->query, array( 'post_type' => 'product' ) );
query_posts( $args );

To use your custom arguments, for example:

// Globalize $wp_query
global $wp_query;
// Define custom query args
$custom_query_args = array(
    'meta_key' => 'post_views_count',
    'order' => 'DESC'
);
// Merge custom query args with default query
$custom_query = array_merge( $wp_query->query, $custom_query_args );
// Query posts based on modified query arguments
query_posts( $custom_query );

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 use WP_Query() or get_posts().

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.