Ready to get started?Download WordPress


Post Timeline (3 posts)

  1. aneemal
    Posted 2 years ago #

    Hi all,

    I hope I'm posting this in the right place. I was hoping to get some help in creating a 'post timeline' to display previous posts on my blog, underneath the current post.

    This is what I'd like it to look like, where the numbers are the dates of the posts:
    ^ LATEST | 18 | 6 | < MAR | 28 | 14 | 10 | < FEB | 30 | 7 | 2 | < JAN |

    	global $post;
    	$tmp = $post;
    	$args = array( 'numberposts' => 10 );
    	$myposts = get_posts( $args );
    	$currMonth = date('M');
    	foreach( $myposts as $post ) : setup_postdata($post);			if ($post->ID == $do_not_duplicate) continue;
    		   if (the_time('M') != $currMonth) { ?>
    		      <li><?php the_time('M'); ?></li>
    		   <? }; ?>
                         <li><a href="<?php the_permalink(); ?>"><?php the_time('jS'); ?></a></li>
    	$post = $tmp;

    This works to a degree, but it shows the month alongside each post date. I wonder if I have to create a variable to store the last month displayed, so that the result only outputs when the value changes?

    Any help would be appreciated!


  2. tugbucket
    Posted 2 years ago #

    Found some code floating around and modded it some. I think this does what you want:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

  3. tugbucket
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic