views:

54

answers:

1

I am looking to display archives pages as a normal posts page...

So, a posts page with a secondary navigation showing:

LATEST POSTS / LAST MONTH / LAST YEAR / OLDER

On each of those pages, I would like to display a summary of each post just like the standard latest news page. When you click through you get to the full post.

For each of menu items I have created seperate page templates such as archives_month.php, Then in the template instead of using <?php wp_get_archives I have been using <?php query_posts and adding some time params but unfortunately I have no found the best / correct way to get these yet.

I have one script that works:

<?php if (have_posts()) : ?>
<?php $current_month = date('m');?>
<?php $current_year = date('Y');?>
<?php $current_year = $current_year - 24;?>
<?php query_posts("cat=5&year=$current_year&monthnum=$current_month");?>

For the LAST MONTH page. But I now cannot use this for LAST YEAR and OLDER posts.

Can anyone help me? I've looked into a number of different ways to do it but on some blogs it's not clear and most people just retrieve a list of archives rather than displaying the posts.

Thanks in advance. Mel

A: 

You should be able to put something together using query_posts() as described here.

An example from the linked page for building a query fetching all posts in March 2009:

<?php
//based on Austin Matzko's code from wp-hackers email list
  function filter_where($where = '') {
    //posts for March 1 to March 15, 2009
    $where .= " AND post_date >= '2009-03-01' AND post_date < '2009-03-16'";
    return $where;
  }
add_filter('posts_where', 'filter_where');
query_posts($query_string);
?>

you will find it easy to adjust.

The output can then be done using The Loop:

// the Loop
while (have_posts()) : the_post(); 
  // the content of the post
  the_content('Read the full post »'); 
endwhile;

For more info on how to customize the stuff displayed in The Loop (to show the summary you talk about) see here.

Pekka
Hiya, Thanks for the response but I saw this and tried implementing it. I'm unsure how this should be implemented as I'm not so familiar with php. I put all this code within my archive_year.php file and within the loop. Can you show me an example of where I need to put the above code snippet from Austin Matzko? Thanks in advance!!Mel
missmonkee
@missmonkee I'm not deeply enough into WP templating right now to make a complete example, but you should be able to drop the 1st code block into any template file that uses The Loop (`while(have_posts()): ....`) and it should filter the list down to the period specified.
Pekka
Unfortunately this does not seem to work ?><?phpfunction filter_where($where = '') {//posts for May 1 to May 15, 2009$where .= " AND post_date >= '2010-05-01' AND post_date < '2010-05-15'";return $where;}add_filter('posts_where', 'filter_where');query_posts($query_string);?><?php the_content('Read more »'); ?><?php endwhile; ?>Can you see any problem with that? I've checked my admin and I do have posts for that period but no error msgs occur. HELP!
missmonkee