last post from each category, impossible?
-
I’d been trying to get the last post from each category in a “page”, and even if I were able to make 2 different loops on the same page (1 for loading the requested page and the other for the blogs from each cat) I couldn’t make the neccesary loop for cycling thru the cats and read the last post.
I’ve got some help from mores but the script didn’t work. It just reads the requested page, even removing the first loop and leaving the cats one.
The test page is at here
and should replace this current messy version (Blogs show up when clicking the “Articles” tab below the flash header.<?php /* Template Name: FirstPostOfEachCategory */ ?> <?php get_header(); ?> <div id="content"> <div id="main"> <?php // Here we output the actual content of the Page. If you need introductory text or something if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h1><?php the_title(); ?></h1> <?php the_content(); ?> <?php endwhile; else: endif; ?> <?php // this is where the categories get cycled through and the latest X posts of each are displayed $categories = $wpdb->get_results("SELECT $wpdb->terms.term_id AS id, name, description, term_order from $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE taxonomy = 'category' AND parent = 0 ORDER BY term_order ASC"); foreach ($categories as $category) { ?> <h1>Category: <a href="<?php echo get_category_link($category->id); ?>"><?php echo $category->name; ?></a></h1> <?php query_posts('category_name='.$category->name.'&showposts=1'); } ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php the_title(); ?> <!-- Style this any way you want --> <?php endwhile; else: ?><p>Nix!</p><?php endif; ?> </div> <?php } ?> </div> </div> <?php get_footer(); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘last post from each category, impossible?’ is closed to new replies.