Spice Up Your Archives with a Timeline

I’ve always loved the following Timeline Archive as shown here. The code is provided here.

I use Headway but have no idea how to implement it so my archive looks much better than the current standard ones I can use.

- Stuart Wooster, StuartWooster.com

In today’s post, we’re going to take a look at how you can spice up your archive page using the timeline style Stuart has shared with us in the links above.

 

(Reading this in an RSS reader? Click here to see the video.)

While attempting to set this timeline up according to the tutorial above, I ran into a very odd problem. For whatever reason, the when the code queries my blog posts and pulls the dates for each, it’s saying they were all published in 1970. For that reason, I’ll instead show you how I’ve created the Archive page for my personal blog. It’s similar to Stuart’s link except it doesn’t take into account the number of days passed between posts.

The PHP Code

In your WordPress dashboard, go to Pages > Add New and create a page called Archives or whatever you want your archive page to be titled. Once it’s created, open up the Headway Visual Editor and go to the newly created page. You can go ahead and delete the content leaf that’s there. In its place, add an HTML/PHP leaf.

Once the leaf is on the page, click the pencil icon to edit it. Then paste in this code:

<table><span>2011</span><?php query_posts('year=2011&posts_per_page=-1'); ?><?php while (have_posts()) : the_post(); ?>               <tr>                  <td><?php the_date('j M', '<span>', '</span>'); ?></td>                  <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td></tr>     <?php endwhile; ?></table>
<table><span>2010</span><?php query_posts('year=2010&posts_per_page=-1'); ?><?php while (have_posts()) : the_post(); ?>               <tr>                  <td><?php the_date('j M', '<span>', '</span>'); ?></td>                  <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td></tr>     <?php endwhile; ?></table>

<table><span>2009</span><?php query_posts('year=2009&posts_per_page=-1'); ?><?php while (have_posts()) : the_post(); ?>               <tr>                  <td><?php the_date('j M', '<span>', '</span>'); ?></td>                  <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td></tr>     <?php endwhile; ?></table>

In this case, you’ll notice that the years are manually set. Obviously, this isn’t an ideal solution, but since you would only have to update it once a year it’s not much of a hassle. For every year you’ve posted on your blog, you should copy and paste a new line at the bottom and replace both the years with the applicable year.

The CSS

You can paste this code in by going to Tools > Live CSS Editor in the top menu of the Headway Visual Editor. This code is exactly the code I use on my personal blog, so you’ll have to swap out the leaf number (91) with the number of the leaf you added to your archive page. If you’d like to style your archive page a different way, check out CSS for Beginners. A little bit of tweaking can go a long way!

div#leaf-91 div.leaf-top { display: none; margin-left: -3px; border-bottom: none; }div#leaf-91 table { margin-top: -8px; width: 400px; margin-bottom: 50px; float: left; font-size: 14px; margin-left: 20px; line-height: 1.5em;}div#leaf-91 table td.td-date { width: 50px; padding-right: 20px; text-align: right;}div#leaf-91 table td.td-title.view-all { font-family: sans-serif; padding-top: 10px !important; }div#leaf-91 table td.td-title, div#leaf-91 table td.td-date { font-size: 12px; padding-top: 0px; }
div#leaf-91 div.leaf-content a{ font-family: sans-serif; color: #99aa66; text-decoration: none; }div#leaf-91 div.leaf-content a:hover{ color: #555; border-bottom: thin solid #99aa66; padding-bottom: 1px;}div#leaf-91 span.td-year { font-size: 30px; float: left; }
span.arc-date { font-family: sans-serif; color: #bbb;} div#leaf-91 span { float: left; }

UPDATE: I missed a piece of the CSS code so years weren’t displaying correctly. This is now fixed.

For more design tips and tricks like this, be sure to subscribe to Blog Design Guy. If you have your own blog design question, feel free to contact me via the Free Help page or by using the form below.

Oops! We could not locate your form.


Similar Posts:

    None Found



Post comment as twitter logo facebook logo
Sort: Newest | Oldest
StuartWooster 6 pts

Hi JD,

The code works fine but I'm having some CSS issues with the years not displaying correctly.

I tried the other code from the other site too... I found I could get the year to change from 1970 by altering the Y in the following line to the current year:

$post_year = date( 'Y', $post_ts );

The trouble was it did not create a new year further down the list of posts.

jdbentley 14 pts

StuartWooster Yeah, if you input the year directly then it can't pull it dynamically. I'm not enough of a programmer to figure out exactly why it won't do that. I hope someone smarter can chime in.

What is the problem with the years exactly? Is the page online now?

StuartWooster 6 pts

jdbentley Yep it is live: http://stuartwooster.com/archive

As you can see it is moving them all to the top.

jdbentley 14 pts

StuartWooster Looks like I missed a piece of code. In your case you need to add div#leaf-50 span { float: left; } and that will put them in the right place. I'll update the CSS in the post, too.

StuartWooster 6 pts

jdbentley You star!Thanks for helping me out with this question.

Which part of the CSS controls the design/font size of the years? Or is that further code I need to add?

jdbentley 14 pts

StuartWooster The CSS I just posted for you actually controls every aspect of the years, not just the float. So within those brackets you can adjust the margins (if you want it to the left of the posts like mine are), the colors, fonts, etc.

Trackbacks

  1. […] I might suggest that you create a custom archive page, use Headway to create custom sneeze pages or install some plugin. However, using WordPress.com […]