Title: Problem with tag.php
Last modified: August 20, 2016

---

# Problem with tag.php

 *  Resolved [mexxa84](https://wordpress.org/support/users/mexxa84/)
 * (@mexxa84)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/problem-with-tagphp/)
 * This is what I use for the archive, tag, date,…
 *     ```
       <?php
       	$temp = $wp_query;
       	$wp_query= null;
       	$wp_query = new WP_Query();
       	$wp_query->query('showposts=5'.'&paged='.$paged);
       	?>
       	<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
       	<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
       ```
   
 * It works for everything but the tag template. When you go to a specific tag it
   shows all posts instead of only the posts with that particular tag.
    What am 
   I doing wrong?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/problem-with-tagphp/#post-3019756)
 * It’s doing exactly what you told it to do – show 5 posts from **all** posts. 
   If you simply want to modify the number of posts shown in the tag template, you
   can just use `query_posts( $query_string . '&posts_per_page= 5' );` before the
   standard Loop. [WP_Query](http://codex.wordpress.org/Function_Reference/WP_Query)
   should only be used for secondary Loops.
 *  Thread Starter [mexxa84](https://wordpress.org/support/users/mexxa84/)
 * (@mexxa84)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/problem-with-tagphp/#post-3019761)
 * Sorry for my lack of understanding and thank you for your time.
    Why is it that
   when I use this with a date or category it only shows the posts in that date 
   and category but when I do a tag it always shows all posts instead of just posts
   with that tag?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/problem-with-tagphp/#post-3019763)
 * It depends upon what template you are modifying and how/where. In general, if
   you want to modify the main query a little, use query_posts() and the approach
   I suggested above.
 *  Thread Starter [mexxa84](https://wordpress.org/support/users/mexxa84/)
 * (@mexxa84)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/problem-with-tagphp/#post-3019764)
 * By the way, I replaced my code with yours and it works just fine now on the tag
   template. I am going to see if it works on the other templates as well.
 *  Thread Starter [mexxa84](https://wordpress.org/support/users/mexxa84/)
 * (@mexxa84)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/problem-with-tagphp/#post-3019783)
 * Now I understand what I did wrong. Thank you esmi.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/problem-with-tagphp/#post-3019805)
 * Glad I could help 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Problem with tag.php’ is closed to new replies.

 * 6 replies
 * 2 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/problem-with-tagphp/#post-3019805)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
