Hello,
i have the folowing code
<?php query_posts('category_name=calendar&showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a> </li>
<?php endwhile; ?>
i want to show posts from the current month - what code do i need to add to the above ??
i also have the same code but i need to show posts from the past month(s)....
have you tried to work with the time parameters of query_posts() ?
http://codex.wordpress.org/Function_Reference/query_posts#Time_Parameters
for the current month maybe something like (untested):
<?php $today = getdate();
query_posts('category_name=calendar&posts_per_page=5&year=' . $today["year"] ' . monthnum=' . $today["mon"] ); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a> </li>
<?php endwhile; ?>
for last month maybe (untested):
<?php $today = getdate();
$year = $today["year"];
$last_month = $today["mon"] - 1;
if( $last_month == 0 ) {
$last_month = 12;
$year = $year - 1;
}
query_posts('category_name=calendar&posts_per_page=5&year=' . $year . 'monthnum=' . $last_month ); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a> </li>
<?php endwhile; ?>
thanks but i get some syntax error when i use the sample code
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING