[wp-hackers] Too Many Queries

Andy Mikester andymikester at gmail.com
Wed Dec 6 23:30:17 GMT 2006


Thanks so much Mark, I really appreciate you taking the time to help me out.
The problem is my <--do stuff--> doesn't play nice with your code, here is a
sample of the full code I am using to display the posts,  all 12 months are
not included because it would be extremely long, just the first 2 from 2006
and 1 from 2005:

<div class="entries">
                    <h5><a name="06" id="06">2006</a></h5>
                    <?php
                    query_posts('cat=2&year=2006&monthnum=1');
                    if ($wp_query->post_count >= 1)
                    {
                    ?>
                        <dl>
                            <dt><?php the_time('F') ?></dt>
                            <?php if (have_posts()) : while (have_posts()) :
the_post();?>
                            <dd><a href="<?php the_permalink() ?>"
rel="bookmark" title="<?php the_title(); ?>"><span
class="comments_number"><?php comments_number('0', '1', '%', '');
?></span><span class="date"><?php the_date('j','',''); ?></span><?php
the_title(); ?></a></dd>
                            <?php endwhile; endif; ?>
                        </dl>
                    <?php
                    }
                    ?>
                    <?php
                    query_posts('cat=2&year=2006&monthnum=2');
                    if ($wp_query->post_count >= 1)
                    {
                    ?>
                        <dl>
                            <dt><?php the_time('F') ?></dt>
                            <?php if (have_posts()) : while (have_posts()) :
the_post();?>
                            <dd><a href="<?php the_permalink() ?>"
rel="bookmark" title="<?php the_title(); ?>"><span
class="comments_number"><?php comments_number('0', '1', '%', '');
?></span><span class="date"><?php the_date('j','',''); ?></span><?php
the_title(); ?></a></dd>
                            <?php endwhile; endif; ?>
                        </dl>
                    <?php
                    }
                    ?>
              <p><a href="#content">back to top</a></p>
</div><!--end entries06-->

<div class="entries">
                    <h5><a name="05" id="05">2005</a></h5>
                    <?php
                    query_posts('cat=2&year=2005&monthnum=1');
                    if ($wp_query->post_count >= 1)
                    {
                    ?>
                        <dl>
                            <dt><?php the_time('F') ?></dt>
                            <?php if (have_posts()) : while (have_posts()) :
the_post();?>
                            <dd><a href="<?php the_permalink() ?>"
rel="bookmark" title="<?php the_title(); ?>"><span
class="comments_number"><?php comments_number('0', '1', '%', '');
?></span><span class="date"><?php the_date('j','',''); ?></span><?php
the_title(); ?></a></dd>
                            <?php endwhile; endif; ?>
                        </dl>
                    <?php
                    }
                    ?>
                    <p><a href="#content">back to top</a></p>
</div><!--end entries05-->

So I need to be able to output a <dl> for every month of 2006 and keep in
the 2006 DIV, and then output a <dl> for every month of 2005 and keep it in
the 2005 DIV, and so on and so on. Right now the method above works but I am
querying the database 24 times every time the page is loaded, and the number
will keep going up as time goes on.

Any more help would be greatly appreciated.

Thanks Again,
Andy


More information about the wp-hackers mailing list