Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Dynamic query_posts agrument for category archives WordPress

  • SOLVED

Hello everyone,

I hope the title somewhat makes sense. I am modifying a website using WordPress and Thesis, and I am utilizing the Custom Loop API that Thesis offers in order to have custom category archives that pull in custom fields. Here is my issue, though. The Custom Loop API is pretty powerful, and completely overrides the default archives loop.

I have setup this custom Thesis loop as follows (don't worry if it looks funny - it's just how the API works).

class my_loops extends thesis_custom_loop {
function archive() {
if(is_archive()) { ?>
<?php thesis_archive_intro(); ?>
<ul class="portfolio-archives">
<?php
query_posts($query_string . '&$paged');
$slidenumber = 1;
while(have_posts()) : the_post();
$portfolioimage = get_post_custom_values($key = 'portfolioimage');
?>
<li class="slide-<?php echo $slidenumber++; ?>">
<?php if(isset($portfolioimage[0]) && strcmp($portfolioimage[0],'')!= 0) { ?>
<a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php echo $portfolioimage[0]; ?>" class="captify small portfolio" alt="<?php the_title(); ?>" width="189px" height="107px" /></a>
<?php } ?>
</li>
<?php endwhile; ?>
</ul>
<?php }
}
}
$loopty_loop = new my_loops;


As you can see, in the query_posts() argument, all I have done is replicated the main loop and added pagination. The problem with this is that it displays the exact same loop on every archives page regardless of what category or other custom taxonomy you are viewing. This is where I need help. I don't know how to set it up to where it can be dynamic. I know I could use conditional statements to target specific things, but that is not efficient nor necessary (I don't think). I want the loop to be able to display the posts based on the category or taxonomy being viewed.

I hope this makes sense. I think it simply has to do with some query_posts argument, I just don't know what exactly that is.

You can view an example [[LINK href="http://shooters.tgmtestserver.com/category/editorial/"]]here[[/LINK]] and [[LINK href="http://shooters.tgmtestserver.com/editors/mark-hutchinson/"]]here[[/LINK]]. Notice that both are showing the exact same loop, but they are for different categories/taxonomies. I want the loop to display the corresponding category/taxonomy posts.

Let me know if you need more information!

Thomas

Answers (1)

2011-02-27

Hai Bui answers:

Hello Thomas,

I think the problem is the function don't get the existing query parameters ($query_string).
I'm not sure it would solve the problem but please try adding:

global $query_string;

before

query_posts($query_string . '&$paged');

so it becomes:

global $query_string;
query_posts($query_string . '&$paged');


Let me know if it works or not. We can use another method if it doesn't.

Hai