StylizedWeb is a blog about web trends and tutorials, KnowHow community forum designed and maintained by Dejan Cancarevic who also runs Serbian IT job board at itPoslovi.info

Categories Archive

Popular Posts
Advertisement
Free Photoshop Tutorials Advertise on Stylized Web Najbolje ponuda IT poslova u Srbiji na itposlovi.info Advertise on Stylized Web
Wordpress Archive page
add to Save to Delicious Save to Stumble Save to Digg
Digg this

Since lot of people asked me how i have made my archives page http://stylizedweb.com/archive/ i realized that they are not really familiar with page templates so i looked over the web for some tutorials and i really couldn't find good ones, so this tutorial will shortly explain how to do it.

If your Wordpress blog is getting bigger archive page is really good to have, and here you can list all your posts, months, weeks what ever you want. If you are using some free template look in the theme folder because you could already have it, if you don't here's how to make it.

1. Open your index.php page and save it as archive.php
2. Replace the original loop code with some of these examples (it starts with <?php while(have_posts()) : the_post(); ?> and ends with <?php endwhile; ?> so everything between that)

 
<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<ul>
<?php
$myposts = get_posts('numberposts=100&offset=0');
foreach($myposts as $post) :
?>
<li><?php the_time('d.m.y') ?> | <a href="<?php the_permalink(); ?>"><? php the_title(); ?></a></li>
 
<? php endforeach; ?>
</ul>
 
<?php endwhile; ?>
 

This will list all posts like on http://stylizedweb.com/archive/ you can change offset (number to start from) etc, more on Wordpress codex about it http://codex.wordpress.org/Template_Tags/get_posts. This second code will list categories and month archives.

 
<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<ul><?php wp_list_cats(’sort_column=name&optioncount=1) ?></ul>
<ul><?php wp_get_archives(’type=monthly&show_post_count=1) ?></ul>
 
<?php endwhile; ?>
 

3. Add this code at the top of your archive.php page

 
<?php
/*
Template Name: Archives Page
*/
?>
 

4. Upload archive.php to your theme folder
5. Create a new page and Archives Page from the page templates

Page template

Of course if you don't like saving index file as archive you can start from the making a new page and adding all these things.

What do you think?





15 Responses so far

By Dejan
on April 14, 2008

try this before foreach
<?php $myposts= array_reverse($myposts, true); ?>

By James
on April 14, 2008

Sorry, I meant how did you order it with the latest posts at the top. When I try to use the argument from the get post page on Wordpress it doesn’t work. Thanks.

By Dejan
on April 14, 2008

James
What do you mean ordered list? This is ul with simple text for dates, please explain

By James
on April 14, 2008

Hey

Can you tell me how your ordered your list? I’ve tried using the order argument for ordering the dates similar to yours but nothing seemed to work. Thanks for the help, but this little bit is driving me nuts.

By Yan
on March 29, 2008

Thanks for the tutorial. Just wanna know how could I create archive of pages instead of posts?

By Jermayn Parker
on March 12, 2008

Yeah agree that this type of tut is fairly minimal on the web!
I had to find a theme and copy it for how to do it.

By Stan
on March 9, 2008

very useful, your archive page looks good, thanks

By Marko
on March 8, 2008

good tutorial, thanks!

By Sarah
on March 8, 2008

Awesome! Just what i was looking for, thanks!

  1. Jun 27, 2008: ArtsLab
  2. Jun 14, 2008: Useful WordPress Tricks | StylizedWeb.com
  3. Jun 12, 2008: Digg Top OffBeat News of all times » Wordpress Archive page
  4. Jun 12, 2008: Peter Gamez » Wordpress Archive page
  5. Mar 29, 2008: Web 2.0 & Usability Blog by Adam Moss » Blog Archive » 10 Blog Usability Guidelines
  6. Mar 8, 2008: WP Archive page