views:

18

answers:

1

Hello,

What is the php code that I need to write to display the last 5 blog posts from each category on my wordpress blog?

I only want to include the title of the blog post, date and name of author (no image from blog post).

An example of exactly what I want to do is in this theme, under the name 'LATEST POSTS IN XXXXX CATEGORY' http://sponsoredwp.info/brightness/

Thanks!

A: 

Firstly you want to take a look at the get_categories function:

http://codex.wordpress.org/Function_Reference/get_categories

Then you should look at get_posts function:

http://codex.wordpress.org/Template_Tags/get_posts

a small example:

$args = array('orderby' => 'name','order' => 'DESC');
foreach(get_categories($args) as $category)
{
    //Here you want to print out a header for your category

    $my_query = new WP_Query('category_id='.$category->id.'&showposts=1');
    while($my_query->have_posts()):
        $my_query->the_post();
        //Here you want to use the functions like the_title() and the_permlink()
        //So you can itterate you results
    endwhile;
}
RobertPitt