monthly post timeline for wordpress

How can i use code from http://astheria.com/this-site/creating-a-timeline-style-archive-page (Demo for yearly archive) to show posts on several month instead of year? for example i have 3 posts in jun 2015. and 2 posts in jan 2016 i want to sort posts in month. like below

  1. jun 2015
    • post1
    • post2
    • post3
  2. jan 2016
    • post4
    • post5

this is code for yearly archive:

Read More
<?php get_header(); query_posts('posts_per_page=-1');
	$dates_array 			= Array();
	$year_array 			= Array();
	$i 				= 0;
	$prev_post_ts    		= null;
	$prev_post_year  		= null;
	$distance_multiplier 	        = 2;
?>

	<?php while (have_posts()) : the_post();

		$post_ts    =  strtotime($post->post_date);
		$post_year  =  date( 'Y', $post_ts );

		/* Handle the first year as a special case */
		if ( is_null( $prev_post_year ) ) {
			?>
			<h3 class="archive_year"><?=$post_year?></h3>
			<ol class="archives_list">
			<?php
		}
		else if ( $prev_post_year != $post_year ) {
			/* Close off the OL */
			?>
			</ol>
			<?php

			$working_year  =  $prev_post_year;

			/* Print year headings until we reach the post year */
			while ( $working_year > $post_year ) {
				$working_year--;
				?>
				<h3 class="archive_year"><?=$working_year?></h3>
				<?php
			}

			/* Open a new ordered list */
			?>
			<ol class="archives_list">
			<?php
		}

		/* Compute difference in days */
		if ( ! is_null( $prev_post_ts ) && $prev_post_year == $post_year ) {
			$dates_diff  =  ( date( 'z', $prev_post_ts ) - date( 'z', $post_ts ) ) * $distance_multiplier;
		}
		else {
			$dates_diff  =  0;
		}
	?>
		<li style="margin-top:<?=$dates_diff?>px"><span class="date"><?php the_time('F j'); ?><sup><?php the_time('S') ?></sup></span> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
	<?php
		/* For subsequent iterations */
		$prev_post_ts    =  $post_ts;
		$prev_post_year  =  $post_year;
	endwhile;

	/* If we've processed at least *one* post, close the ordered list */
	if ( ! is_null( $prev_post_ts ) ) {
		?>
	</ol>
	<?php } ?>

Thanks .
best regards.

Related posts