Wordpress: Display Latest Blog Posts on Any Wordpress Page


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



Copy this code and paste it in your HTML
  1. <?php
  2. $args = array( 'posts_per_page' => 10, 'order'=> 'ASC', 'orderby' => 'title' );
  3. $postslist = get_posts( $args );
  4. foreach ($postslist as $post) : setup_postdata($post); ?>
  5. <div>
  6. <?php the_time(); ?>
  7. <?php the_title(); ?>
  8. <?php the_excerpt(); ?>
  9. <?php the_category(', '); ?>
  10. </div>
  11. <?php endforeach; ?>
  12.  
  13.  
  14.  
  15. Notice the div around the_time, the_title, the_excerpt and the_category. You can wrap html elements to fit and style any of these functions.
  16.  
  17. the_time will display the time of the post. use the_time instead of the_date.
  18. http://codex.wordpress.org/Formatting_Date_and_Time
  19.  
  20. the_title will display the post title.
  21.  
  22. the_excerpt will display the post excerpt which defaults to 55 characters unless specified by a filter in functions.php. currently the twenty-ten theme sets the excerpt character limit.
  23.  
  24. the_category will display which categories the post is in, if any.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.