I don’t think there is such a query in WP… unless you build it.
Know ye a way of building such a query?
While in the Loop, you can assign month and year of your post to variables:
<?php $month = the_time('m');
$year = the_time('Y'); ?>
AFTER that, use query_posts()
to retrieve other posts from the displayed post’s month/year.
Thanks sivar I’ll give this a whirl.
These variables do not seem to assign for some reason.
<?php $month = the_time('m');
$year = the_time('Y'); ?>
<?php echo $month; ?>
This displays nothing.
Ok you’ve got to use ‘get_the_time’.
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
/* get the month and year */
<?php $thispostsmonth = get_the_time('m'); ?>
<?php $thispostsyear = get_the_time('Y'); ?>
/* get first category id */
<?php
$cat = get_the_category(); $cat = $cat[0]; $firstcat = $cat->cat_ID; $secondcat = $cat->cat_name;
?>
/* show the post */
<h1><a href="<?php the_permalink(); ?>" rel="tag"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
/* show the post */
<h3><?php echo $secondcat; ?></h3>
<ul>
<?php query_posts("cat=$firstcat"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<li><a style="color:#cc0066;" href="<?php the_permalink(); ?>" rel="tag"><?php the_title(); ?> </a></li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
/* ############# Display The Posts From The Same Month And Year ############# */
<ul>
<?php query_posts("year=$thispostsyear&monthnum=$thispostsmonth&showposts=-1&order=DESC"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<li><a style="color:green;"href="<?php the_permalink(); ?>" rel="tag"><?php the_title(); ?> </a> <span><em><?php the_time('F j, Y'); ?></em></span></li>
<?php endwhile; ?>
<?php endif; ?>
</ul>