Posted By

miziomon on 12/28/08


Tagged

wordpress archives


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

thesbrown


wordpress better archived


 / Published in: PHP
 

URL: http://maurizio.mavida.com

wordpress function return html list with all posts grouped by month

  1. /*
  2. * 20.12.2008 | maurizio
  3. * return html list with all posts grouped by month
  4. */
  5. function wp_getallpost() {
  6. // variables declaration
  7. $archives = "";
  8. $monthname = "";
  9. // get all posts
  10. $lastposts = get_posts('numberposts=-1&orderby=date');
  11. foreach($lastposts as $post) :
  12. $month = mysql2date('m', $post->post_date );
  13. $year = mysql2date('Y', $post->post_date );
  14. if ( $monthname <> mysql2date('F', $post->post_date ) ) {
  15. // check if i need to close list
  16. if ( $monthname != "" ) { $archives .= "</ul>"; }
  17. $archives .= "<p><strong><a href='".get_month_link($year, $month)."'>";
  18. $archives .= mysql2date('F Y', $post->post_date );
  19. $archives .= "</a></strong></p>";
  20. $archives .= "<ul class='ba-single-column'>";
  21. // change current month
  22. $monthname = mysql2date('F', $post->post_date );
  23. }
  24. $archives .= "<li>";
  25. $archives .= mysql2date(' d | ', $post->post_date );
  26. $archives .= "<a href='" . get_permalink($post->ID) . "'>" . $post->post_title . "</a>";
  27. $archives .= "</li>";
  28. endforeach;
  29. $archives .= "</ul>";
  30. return $archives;
  31. }

Report this snippet  

You need to login to post a comment.