Multiple Loops problem
-
Howdy
What I’m trying to do is add a list of links to posts in a specific category at the bottom of all the posts that are in that specific category.
I’m editing single.php to try and do this. Here’s the code I’m using:
if (in_category(643)) { $myQuery = new WP_Query('category_name=f22'); echo "Here's the links to the other images in this project ..."; echo '<ul style="margin-left: 30px">'; while ($myQuery->have_posts()) : $myQuery->the_post(); $tempID = get_the_ID(); echo '<li><a href="/blog/index.php?p='.$tempID.'">'; echo the_title(); echo '</a></il>'; endwhile; echo '</ul>'; }
This code lists the links to the posts in the category fine; the problem I’m having is that once the loop has finished, the rest of the post thinks that it’s the first post in the category rather than the post that it started out being before I started looping out links to the other posts in the category. If that makes sense.
Here you can see what I mean – the first post in the category ‘f22’ on my photoblog was posted on the 8th Jan, you can see it here:
https://chris-beaumont.com/blog/index.php?p=847
Then if you look at all the other posts in the same ‘f22’ category, you can see that they all appear to have been posted on the 8th Jan, and have all the same metadata, even though they weren’t posted on the 8th Jan, and don’t have the same metadata:
https://chris-beaumont.com/blog/index.php?p=959
https://chris-beaumont.com/blog/index.php?p=969
https://chris-beaumont.com/blog/index.php?p=977They also have the same ‘Test Comment’ at the bottom of every page, even though the ‘Test Comment’ has only been posted on the first post in the category. This is because the date, all the meta data, and the comments, are all rendered out of single.php after the code loop I’ve put in to list links to the other posts in the category.
So my question is – how the conk do I stop the loop that I put into single.php from affecting the code that comes after it? I’ve tried all the methods that are listed on this page https://codex.www.ads-software.com/The_Loop regarding Multiple Loops, but nothing seems to work.
Any help is much appreciated.
- The topic ‘Multiple Loops problem’ is closed to new replies.