Best way to do multiple separate queries?
I’m building a new WP 2.0.4 blog which needs to support multiple authors plus “staff” content. “Authors” will be 3rd-party users in the “Authors” role, and “Staff” will be our own folks in the “Editor” or “Admin” role. “Authors” can only post to a single category, enforced by Owen Winkler’s Limit Categories plugin; “Staff” can post to a variety of categories.
I need some advice on the most efficient way to structure my home page. My specs call for a number of separate blocks of content:
1) a block with excerpt from the latest post in Category=”News”
2) a block with excerpt from 2 stories: of the 3rd-part authors, show the latests single post from each of the latest authors to post. I.e., if Tom, Dick and Jane each wrote some posts in this order:
Tom – post 1, Dick – post 1, Jane – post 1, Jane – post 2
Jane’s Post 2
Dick’s Post 1
3) a block with the latest post in another category
4) a block with the latest post in yet another category
5) the excerpt from a specific Page
6) the excerpt from another specific Page
and so on.
Right now, I have a home.php template in which I’m using several techniques:
I restart the Loop each time I want the latest post in a category, so I have several places on the page with
<?php query_posts('category_name=news&showposts=1'); while (have_posts()) : the_post(); ?>
<div id="news">post tags for excerpt, permalink, etc....</div>
<?php endwhile; ?>
and for the Page excerpts, I’m using Kafkaesqui’s Get-a-post plugin, so I have several calls like:
<?php if(function_exists('get_a_post')) get_a_post('feature-promo') ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php edit_post_link(); ?>
My home currently has 6 query_posts() calls to get the latest post in a specific category, and 3 calls to Get-a-post to get specific Page excerpts — and I haven’t yet implemented the latest-post-by-2-different-authors feature yet.
Is this the right approach to constructing a page like this?
WordPress sez it takes 48 queries in 0.3 seconds to build this page. I don’t have a sense for how this compares to other pages like this, but it seems like a fairly high number of queries. What;s the best way to implement a page like this? I’ve looked at a number of plugins that seem to help select the right stuff for the page, incl. Level 10 Blog Matrix, Get-a-Post, Improved-Include Page (seems like that overlaps Get-a-post), and Posts in Category, but I haven’t settled on an approach yet. Any advice appreciated!
- The topic ‘Best way to do multiple separate queries?’ is closed to new replies.