Wordpress: Featured post and one post from each category

I have a bit of code, but it seems horrendous. I have to include 7 loops - eight categories and a 'featured' post with some special CSS styling.

Can I simplify this? Can I pull the posts out of the SQL database directly, to avoid all the loops, and will that speed up page load times? Is there a plugin that already does some/most of this? Should I be using another CMS? My layout is as follows:

Layout

So, to clarify, each of the 'Category' sections will have only the most recent post from that category. The relevant snip of code:

<?php
while (have_posts()) : the_post();
$feature = get_the_category(); $feature = $feature[0]->cat_ID; ?> <!-- $feature is the ID of the category of the feature post, used later to ensure that the feature post isn't repeated. -->
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php
$arr = array(1, 2); // Grouped into sets of two categories.
foreach ($arr as $catno) {
if ($feature == $catno) { $offset = 1; } else { $offset = 0; } <!-- If feature is in selected category, offset by one so the feature post isn't repeated. -->
query_posts('cat=' . $catno. '&showposts=1&offset=' .$offset);
while (have_posts()) : the_post();
?>
<?php the_excerpt(); ?>
<?php endwhile; } ?>

And the full code. I'm not afraid to play with PHP, but I don't know Wordpress or its hooks (aside from the basic template tags stuff).

Thank you guys, this is my first note!

Leave a Reply




Created by DesignForWeb company. All rights reserved © 2007-2010. Check also the iPhone / iPad developers blog
Disclaimer
The materials collected in this blog were taken from open access sources. We try our best to preserve the copyrights of original authors and clearly state the authorship as well as link to original source website where it's possible. Please leave your comment if you feel offended by any post or if you dispose of any information about breach of copyright law in this blog. We will do our best to resolve the situation immediately.