Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i use almost 10 new WP_Query() in my main page, but the loading is quite slow : do you know what i could do for that? each "new WP_Query()" ends up with a "endwhile" : is that enough? is there anything like reset query possible with WP_Query() ?

you can check my website here : www.pondb.com : it's not finished (and some of the text is missing) but you can see the time to load it, and the source code.

edit: some code from the index.php : (i might erase 1 or 2 queries, but the load time is still like 10 seconds on my computer...)

<!-- ***
////////////
*** PAGE 2 : BIO
////////////
*** -->
<div id="bio">
    <div class="childB">
            <a href="#" class="plus" rel="contact">Contact</a>

            <?php $my_query = new WP_Query('category_name=bio');
            while ($my_query->have_posts()) : $my_query->the_post(); ?> <!-- loop bio -->
        <h2><?php echo get_the_title(); ?></h2> <!-- titre bio -->
                <p><?php the_content(); ?></p> <!-- contenu bio -->
            <?php endwhile; ?>
    </div>
    <div class="childBSide">
            <h2>News</h2>
            <?php query_posts('category_name=news&showposts=3'); ?> <!-- afficher 1ere news -->
            <?php while (have_posts()) : the_post(); ?>
                <h3><?php echo the_title(); ?></h3>
                <p><span class="sous-titre">Posté le <?php echo the_time('j F, Y'); ?></span></p>
                <p><?php the_excerpt(); ?></p>
            <?php endwhile; ?>
            <?php wp_reset_query(); ?> <!-- fin afficher 1ere news -->

            <div class="suite">
                <a href="#" class="plus" rel="news">Lire les news</a>
            </div>
    </div><!-- fin BSide -->
</div>



<!-- ***
////////////
*** PAGE 3 : NEWS
////////////
*** -->
<div id="news">
    <div class="childB">
        <a href="#" class="plus" rel="contact">Contact</a>
        <?php
        $my_query = new WP_Query('category_name=news&showposts=8');
        while ($my_query->have_posts()) : $my_query->the_post(); ?> <!-- loop news -->
        <?php $category = get_the_category();
            if ($category[0]->cat_name <> $sav_category){
                echo "<H2>".$category[0]->cat_name.": </H2><!-- titre catégorie -->";
                $sav_category = $category[0]->cat_name;
            }?><!-- titre news depuis wp -->

                <div class="news">
                <h2><?php echo get_the_title(); ?></h2> <!-- titre de la news -->
                <p><span class="sous-titre">Posté le <?php echo the_time('j F, Y'); ?></span></p> <!-- posté le -->
                <p><?php the_content(); ?></p> <!-- contenu de la news -->
                </div>

            <?php endwhile; ?>
    </div>
    <div class="childBSide">
        <?php $my_query = new WP_Query('category_name=concert');
        while ($my_query->have_posts()) : $my_query->the_post(); ?> <!-- loop concerts -->
            <h2><?php echo get_the_title(); ?></h2> <!-- titre concerts -->
            <p><?php the_content(); ?></p> <!-- contenu concerts -->
        <?php endwhile; ?>
    </div>
</div>

Thanks for your help

share|improve this question

closed as too localized by toscho Jul 14 '12 at 21:49

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Unfortunately looking at front end is pretty much useless for troubleshooting performance. Try to provide some code samples and use one of debug plugins (especially for logging queries) available in official repository. –  Rarst Sep 15 '11 at 21:58
    
@Rarst : thanks Rarst, i edited my post, thanks for your help –  Paul Sep 16 '11 at 0:38

1 Answer 1

Why don't you create a category-bio.php template that uses the normal loop? The Wordpress query will already be built and you won't have to have to create a new query just to do an operation that is already happening already.

You should really look at Wordress' Template Hierarchy http://codex.wordpress.org/images/1/18/Template_Hierarchy.png You can target specific categories with a slug in the file name.

Creating category specific templates will make your theme less expensive memory wise.

share|improve this answer
    
thanks Brian, sorry i don't really understand, you mean create a "bio.php" and include it in the main page? (instead of 10 queries, i woud have 10 "includes" ?) –  Paul Sep 16 '11 at 15:19
    
With the template hierarchy, Wordpress will look for a template called category-bio.php when that category 'bio' is queried on the site. This is a good way not to create another query if you are specifically trying to display 'bio' query results in a different fashion than the archive template. –  Brian Fegter Sep 16 '11 at 16:14
    
thanks , can you tell how to set this up technically? do i have to change something in the code, or if i just have a category-bio.php, it will look for it when i call for a "new query" like i do (in my first post) ? –  Paul Sep 17 '11 at 0:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.