Here is the code I use to show a certain number of the most recent posts including their thumbnails from specific categories in a WordPress website.
To show the 3 most recent posts from Category 1, you would add this code to the appropriate template file of your site:
<?php
//for category 1, show 3 posts
$cat_args=array(
'include' => '1',
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' =>3,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<p><h4>Latest <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.' Posts</a>: </h4></p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<p class="recent-posts"><span class="thumb"><?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?></span>
<span class="recent-post"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></span></p>
<?php
} // foreach($posts
} // if ($posts
} // foreach($categories
?>
You will want to edit the category ID(s) in this code of course so that you call the posts from the correct categories of your site, and you may also want to edit the number of posts shown from the categories as well.
To show the 3 most recent posts from Categories 1, 2, AND 3, you would use this code:
<?php
//for categories 1, 2, and 3, show 3 posts
$cat_args=array(
'include' => '1,2,3',
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' =>3,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<p><h4>Latest <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.' Posts</a>: </h4></p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<p class="recent-posts"><span class="thumb"><?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?></span>
<span class="recent-post"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></span></p>
<?php
} // foreach($posts
} // if ($posts
} // foreach($categories
?>
If you want to include the excerpt of each post, you would use this code:
<?php
//for category 1, show 3 posts
$cat_args=array(
'include' => '1',
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' =>3,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<p><h4>Latest <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.' Posts</a>: </h4></p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<p class="recent-posts"><span class="thumb"><?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?></span>
<span class="recent-post"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></span>
<br/><span class="excerpt"><?php the_excerpt(); ?></span></p>
<?php
} // foreach($posts
} // if ($posts
} // foreach($categories
?>
Let me know if you have any questions or need any further modifications to this code

Get and display the most recent comments from your WordPress blog
Here is the code that I use to get and display the most recent comments from my WordPress blog:
<?php $recent_comments = get_comments( array( 'number' => 5, 'status' => 'approve', 'type' => 'comment' ) ); foreach ($recent_comments as $comment) { ?> <li> <a href="<?php echo get_permalink($comment->comment_post_ID);?>" title="<?php echo $comment->comment_author;?> on <?php echo get_the_title($comment->comment_post_ID); ?>"> <?php echo get_avatar( $comment->comment_author_email, '55' ); ?> </a> <p><b> <?php echo($comment->comment_author); ?> said:</b></p> <p> <?php echo($comment->comment_content); ?> </p> <span style="font-size:12px;font-weight:bold;font-style:italic;"> <a href="<?php echo get_permalink($comment->comment_post_ID);?>#comment-<?php echo $comment->comment_ID;?>" title="<?php echo $comment->comment_author;?> on <?php echo get_the_title($comment->comment_post_ID); ?>"> <?php echo get_the_title($comment->comment_post_ID); ?> </a> </span> </li> <?php } ?> </div>Let me know if you have any questions or need help customizing the code.