Guest User

Untitled

a guest
Aug 11th, 2014
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. function posts_by_year() {
  2. // array to use for results
  3. $years = array();
  4.  
  5. // get posts from WP
  6. $posts = get_posts(array(
  7. 'numberposts' => -1,
  8. 'orderby' => 'post_date',
  9. 'order' => 'ASC',
  10. 'post_type' => 'my-custom-post-type',
  11. 'post_status' => 'publish'
  12. ));
  13.  
  14. // loop through posts, populating $years arrays
  15. foreach($posts as $post) {
  16. $years[date('Y', strtotime($post->post_date))][] = $post;
  17. }
  18.  
  19. // reverse sort by year
  20. krsort($years);
  21. return $years;
  22. }
  23.  
  24. <?php foreach(posts_by_year() as $year => $posts) : ?>
  25. <h2><?php echo $year; ?></h2>
  26. // the code that I need to display the post counts per year
  27. <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment