Hi,
Im building a news website wich is based on wordpress. At the homepage I want to show the news categories. Per category I want to show the latest 5 posts. The first post should show the excerpt and a picture, the rest has to be listed by title.
I am olmost there. The only thing is that i cannot limit the posts per categorie...
Could someone please help me out?
This is what I've got right now...
<?php
/* start of The Loop, Display by Category style */
if (have_posts()) :
/* collect categories */
foreach($posts as $post) :
$category = get_the_category();
if(8 != $category[0]->cat_ID) {
$cats[$category[0]->cat_ID] = $category[0]->cat_name;
$cat_posts[$category[0]->cat_ID] = $post;
}
endforeach;
/* uncomment next line to have categories sort alphabetically */
uasort($cats, strcasecmp);
$cats = array_flip($cats);
/* start of 'display by category' loop */
foreach($cats as $current_cat) :
$current_cat == 0;
?>
<div id="post-<?php the_ID(); ?>">
<h1><?php echo get_the_category_by_id($current_cat); ?></h1>
<?php
/* post loop for each category listing */
$firstpost = true;
foreach($posts as $post) :
the_post();
$category = get_the_category();
if($current_cat == $category[0]->cat_ID) : // if post is in correct category
if ($firstpost == true )
{ ?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<table><tr><td><?php post_image(); ?></td><td><?php the_excerpt_reloaded(15, '', '', true, false, true, 2, true); ?></td></tr></table>
<?php $firstpost = false; ?>
<br />
<?php
}
else
{ ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<?php }
endif; // end 'if post in correct category'
endforeach; // end post loop
echo " </div>";
rewind_posts(); // reset loop for next category
endforeach; // end 'display by category' loop
?>