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.

I use this to call posts:

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$per_page = get_option('to_count_archives');
query_posts("posts_per_page=".$per_page."&paged=".$paged."&cat=".$cat);
if (have_posts())
?>
<?php while (have_posts()) : the_post(); ?>

And it works great for categories. But on archives pages generated for tags it shows ALL posts, not just posts with a specific tag. I am going to creates a separate archives.php and category.php.

I need to keep the to_count_archives part of the code because it calls the number of posts per page.

I appreciate any help rewriting the code above to work correctly.

share|improve this question
    
Does this help? codex.wordpress.org/Tag_Templates –  Rutwick Gangurde Oct 8 '11 at 18:44

2 Answers 2

up vote 1 down vote accepted

It's because when you call query_posts, you're overwriting the original query with a new one, you have to get the original query and reset the things you want to change.

global $query_string;
$per_page = get_option( 'to_count_archives' );
query_posts( $query_string . '&posts_per_page=' . $per_page );
share|improve this answer

Why not use WP_Query and do something like:

// The Query
$the_query = new WP_Query(  array( 'posts_per_page' => 5, 'tag' => 'THETAG' ) );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
    echo '<li>';
    the_title();
    echo '</li>';
endwhile;

You could also do the same thing for category. I hope I understood the question your code sample above confused me. I just find WP_Query easier to use :)

share|improve this answer

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.