• Resolved mexxa84

    (@mexxa84)


    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)
  • 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 should only be used for secondary Loops.

    Thread Starter mexxa84

    (@mexxa84)

    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?

    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

    (@mexxa84)

    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

    (@mexxa84)

    Now I understand what I did wrong. Thank you esmi.

    Glad I could help ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Problem with tag.php’ is closed to new replies.