Wordpress - get posts for a category


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.