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:
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!
