Return to Snippet

Revision: 10423
at December 28, 2008 14:11 by miziomon


Updated Code
/*
* 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;
}

Revision: 10422
at December 28, 2008 14:10 by miziomon


Updated Code
/*
* 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;
}

Revision: 10421
at December 28, 2008 14:01 by miziomon


Updated Code
function wp_getallpost() {
/*
* 20.12.2008 | maurizio
* return html list with all posts grouped by month
*/	
	$archives = "";
	$monthname = "";
	
	$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 ) ) {
			// get_month_link($year, $month)
			
			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'>";
			$monthname = mysql2date('F', $post->post_date ); 	
		}
		
		$archives .= "<li>";		
		//$archives .= date("j" , $post->post_date ) . " | " . $post->post_date . " | " . the_date("j"); 
		$archives .= mysql2date(' d | ', $post->post_date );
		$archives .= "<a href='" . get_permalink($post->ID) . "'>" . $post->post_title . "</a>"; 
		$archives .= "</li>";
		
	endforeach;

		$archives .= "</ul>"; 	

	
	
	return $archives;
}

Revision: 10420
at December 28, 2008 14:00 by miziomon


Updated Code
function wp_getallpost() {
/*
* 20.12.2008 | maurizio
* return html list with all posts grouped by month
*/	
	$archives = "";
	$monthname = "";
	
	$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 ) ) {
			// get_month_link($year, $month)
			
			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'>";
			$monthname = mysql2date('F', $post->post_date ); 	
		}
		
	

	
	
	return $archives;
}

Revision: 10419
at December 28, 2008 13:38 by miziomon


Updated Code
function wp_getallpost() {
/*
* 20.12.2008 | maurizio
* return html list with all posts grouped by month
*/	

	
	return $archives;
}

Revision: 10418
at December 28, 2008 13:15 by miziomon


Initial Code
function wp_getallpost() {
/*
* 20.12.2008 | maurizio
* return html list with all posts grouped by month
*/	

	$archives = "";
	$monthname = "";
	
	$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 ) ) {
			// get_month_link($year, $month)
			
			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'>";
			$monthname = mysql2date('F', $post->post_date ); 	
		}
		
	
		$archives .= "<li>";		
		//$archives .= date("j" , $post->post_date ) . " | " . $post->post_date . " | " . the_date("j"); 
		$archives .= mysql2date(' d | ', $post->post_date );
		$archives .= "<a href='" . get_permalink($post->ID) . "'>" . $post->post_title . "</a>"; 
		$archives .= "</li>";
		
	endforeach;

		$archives .= "</ul>"; 
	
	return $archives;
}

Initial URL
http://maurizio.mavida.com

Initial Description
wordpress function
return html list with all posts grouped by month

Initial Title
wordpress better archived

Initial Tags
wordpress

Initial Language
PHP