• Is there a query that can show all the other posts written that month.

    So I wrote a post on the 4th of December 2006.

    On the post page I’d like to be able to display all other posts written in December 2006.

    If written on the 6th of August 2006 on the post page it would also display all other posts written in August 2006.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I don’t think there is such a query in WP… unless you build it.

    Thread Starter honewatson

    (@honewatson)

    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.

    Thread Starter honewatson

    (@honewatson)

    Thanks sivar I’ll give this a whirl.

    Thread Starter honewatson

    (@honewatson)

    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.

    Thread Starter honewatson

    (@honewatson)

    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>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘All other posts for the month the post was written’ is closed to new replies.