Conflicting Loops?
-
I’m having problem with a conflict somewhere, and I’ve tried reading through the documentation regarding multiple loops but I’m not getting anywhere (PHP isn’t my strong suit).
What I’m trying to do is to have an archive-type index/navigation in the header of my site, showing the 20 latest posts (just date and title). I want this to be displayed in 4 columns, showing 5 posts each. I’ve gotten this to work by using the following code:
<div id="archive-columns"> <div id="column-1"> <?php query_posts('showposts=5'); ?> <?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?> <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?> <p class="archive-date"><?php the_time('F jS, Y') ?></p> <p class="archive-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></p> <?php $count1++; } ?> <?php endforeach; ?> </div><!-- end column-1 --> <div id="column-wrap"> <div id="column-2"> <?php query_posts('showposts=5'); ?> <?php $posts = get_posts('numberposts=5&offset=5'); foreach ($posts as $post) : start_wp(); ?> <?php static $count2 = 0; if ($count2 == "5") { break; } else { ?> <p class="archive-date"><?php the_time('F jS, Y') ?></p> <p class="archive-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></p> <?php $count2++; } ?> <?php endforeach; ?> </div><!-- end column-2 --> <div id="column-3"> <?php query_posts('showposts=5'); ?> <?php $posts = get_posts('numberposts=5&offset=10'); foreach ($posts as $post) : start_wp(); ?> <?php static $count3 = 0; if ($count3 == "5") { break; } else { ?> <p class="archive-date"><?php the_time('F jS, Y') ?></p> <p class="archive-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></p> <?php $count3++; } ?> <?php endforeach; ?> </div><!-- end column-3 --> <div id="column-4"> <?php query_posts('showposts=5'); ?> <?php $posts = get_posts('numberposts=5&offset=15'); foreach ($posts as $post) : start_wp(); ?> <?php static $count4 = 0; if ($count4 == "5") { break; } else { ?> <p class="archive-date"><?php the_time('F jS, Y') ?></p> <p class="archive-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></p> <?php $count4++; } ?> <?php endforeach; ?> </div><!-- end column-4 --> </div><!-- end column-wrap --> </div><!-- end archive-columns -->
The problem is that it breaks the function of the rest of the site – if I visit an individual post page (domain.com/post-name), it displays all the posts, just like the front page does (no comment section, just all posts in a row).
If I remove the archive/nav code from the header, individual post pages show correctly.
I tried initialising a loop at the start of the above code, and I’ve tried the rewind thing, but I’m not sure how to use it all.
So does anyone have a solution to get the above code to work without it conflicting with the rest of the site? What am I doing wrong?
Thanks!
- The topic ‘Conflicting Loops?’ is closed to new replies.