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
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.
精彩评论