Hi,
I’m having a real problem with one of my Wordpress category pages. I use a 3-column grid system on this page and just recently I needed to add an advert to the page, so I thought I would do one query at the top with the first two posts, then add the advert to complete the row. Then I would use a second query underneath creating the posts using the traditional grid system with 3 in each row.
This is working well except for the pagination, which adds the two items form the first query everytime it paginates. You can see this in action at http://soundsandcolours.com/music/
Does anyone know what I can do to make the Pagination ignore the first query, and just keep running the second query instead. I’ve included all of my code below:
1st Query:
$query_string;
$musiccat_posts = new WP_Query($query_string."&posts_per_page=2");
if ($musiccat_posts->have_posts()):
$musiccatIDs = array();
while($musiccat_posts->have_posts()):$musiccat_posts->the_post();
$musiccatIDs[] = get_the_ID();
Hey,
Yeah I’ve tried using both wp_reset_postdata(); and wp_reset_query(); after the first query, right after the endwhile loop as shown below, but it doesn’t seem to make any difference.
Hey WebMachine,
Thanks for the help. In which case, here’s the full code for the page. The page is called loop-ad.php and is called in the category.php page. If you want I can also send the category.php code if that’s of any help. Instead of using the ad code you could always just use a placeholder image with dimensions of 300x250.
I’ll get at it later tonight (my New Year’s Eve fun!). Right now I’m dealing with a couple of projects with today as the deadline. I hope that isn’t too late.
You have the posts displayed three per row. What if you used a slightly different strategy: have only one query with the pagination activated. But use css to restrict the width of the first row so that it contains only two posts, and then use positioning to place the ad where the third spot in the first row is. The rest of the queried posts would continue in their rows of three. That way you won’t have deal with two separate queries. Just a thought.
Yeah sure, that is definitely an option. I was hoping to retain the old way of doing it though, as it would require a lot of work to change the way that the posts are displayed. And, I figured, there must be a logical explanation for why the pagination is continuing both of those queries. But, at the moment, it doesn’t really seem like there’s any possible answer.
Thanks for your help though! And let me know if you have any ideas for why this could be happening. I hope you met your deadlines alright!