Posted By

amyb on 02/04/11


Tagged

wordpress


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

suzt808
Jarek
hariom


Wordpress - get posts for a category


 / Published in: PHP
 

Modify the array to get different number of posts, change the order, change / add categories etc.

  1. <?php
  2. $args = array( 'numberposts' => 3, 'order'=> 'DESC', 'orderby' => 'post_date', 'category' => 7 );
  3.  
  4. $postslist = get_posts( $args );
  5.  
  6. foreach ($postslist as $post) : setup_postdata($post);
  7. ?>
  8.  
  9. <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  10.  
  11. <?php the_excerpt(); ?>
  12.  
  13.  
  14. <?php endforeach; ?>

Report this snippet  

You need to login to post a comment.