• Resolved heyindy

    (@heyindy)


    I am building a magazine style theme, and have come across a stumbling block.
    It’s a soccer blog, so I will give an example of what I mean. Ok so if the user clicks on a “World Cup” tag on the site somewhere I would like the results to be shown in a list with the most recent post for “World Cup” tagged posts displaying with a thumbnail and some copy, and then the rest of the posts falling immediately underneath with no thumbnail image, just the title and excerpt.

    So fundamentally I am asking to use 2 loops on a tag.php page. My problem is that whenever I attempt to use a query post on the first loop the results come back showing all posts.

    Any help would be very gratefully received.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Do you really need two loops, but rather just use a counter with an if statement to decide what to display.

    If you do end up with two loops you many need to add wp_reset_query(); after your first/custom loop to restore the ‘native’ query.

    Thread Starter heyindy

    (@heyindy)

    thank you, I managed to get something working using the following:

    <?php $current_tag = single_tag_title("", false);?>
    <?php $my_query = new WP_Query(array('showposts'=>'1','tag_slug__and'=>array($current_tag),) );
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    <!-- do stuff -->
    <?php endwhile; ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    <!-- do stuff -->
    <?php endwhile; ?>

    That’s obviously using 2 loops, but your method certainly sounds easier. I will look into it thanks so much

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using multiple loops on a tag.php or category.php page’ is closed to new replies.