/ Published in: PHP
wordpress function
return html list with all posts grouped by month
return html list with all posts grouped by month
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * 20.12.2008 | maurizio * return html list with all posts grouped by month */ function wp_getallpost() { // variables declaration $archives = ""; $monthname = ""; // get all posts $lastposts = get_posts('numberposts=-1&orderby=date'); foreach($lastposts as $post) : $month = mysql2date('m', $post->post_date ); $year = mysql2date('Y', $post->post_date ); if ( $monthname <> mysql2date('F', $post->post_date ) ) { // check if i need to close list if ( $monthname != "" ) { $archives .= "</ul>"; } $archives .= "<p><strong><a href='".get_month_link($year, $month)."'>"; $archives .= mysql2date('F Y', $post->post_date ); $archives .= "</a></strong></p>"; $archives .= "<ul class='ba-single-column'>"; // change current month $monthname = mysql2date('F', $post->post_date ); } $archives .= "<li>"; $archives .= mysql2date(' d | ', $post->post_date ); $archives .= "<a href='" . get_permalink($post->ID) . "'>" . $post->post_title . "</a>"; $archives .= "</li>"; endforeach; $archives .= "</ul>"; return $archives; }
URL: http://maurizio.mavida.com