Take the 2-minute tour ×

I currently have a list of archives based on a monthly basis. This is generated using:

<?php wp_get_archives('type=monthly&limit=12'); ?>

This generates a list of months, January 2012, February 2012 and so forth.

Question: What template page does the visitor get directed to when they click on a month?

How can I tweak my existing loop to just show that months posts. My current loop is:

<?php get_header(); ?>


if (is_home()) {

<div class="inner">

<h1><?php trim(wp_title("")); ?></h1>

<?php include ('sidebartwo.php'); ?>

<section class="main-wrap twocol news">

<?php if (have_posts()) : ?>

<article class="box-style">

<time><?php the_time('M d') ?><span><?php the_time('Y') ?></span></time>


<?php the_content(''); ?>


<?php endwhile; ?>                              

<div class="next-prev-wrap">

<span class="next"><?php next_posts_link( 'Older posts', $post->max_num_pages ); ?></span>
<span class="prev"><?php previous_posts_link( 'Newer posts', $post->max_num_pages ); ?></span>



<?php endif; ?>

</div> <!-- /inner -->

</div> <!-- /main -->

<?php get_footer(); ?>
share|improve this question

5 Answers 5

up vote 2 down vote accepted

Ok well it seems the problem code in my loop was where I excluded category 6, here:

if (is_home()) {

I needed to exclude that category so googled how to do so and found this 'Super loop' by Perishable Press, here: http://perishablepress.com/press/2007/08/06/super-loop-exclude-specific-categories-and-display-any-number-of-posts/

Copy pasted that loop and replaced my existing one and all is working now.

share|improve this answer

The code you have pasted, shows the post loop which displayes post title, meta and content. In the question you are asking about the monthly archive list, so please post that part of code where you list the archives.

share|improve this answer
I'm using <?php wp_get_archives('type=monthly&limit=12'); ?> to generate the archive list (i.e. January, February etc.). The other code snippet I've posted is now sitting within my archive.php file but that loop shows all posts not the specific month when a user clicks on any month link generated by wp_get_archives –  egr103 Feb 1 '12 at 15:33

Monthly archives are controlled by the archive.php template file. If that doesn't exist, it goes back to the index.php template.

Ref: http://codex.wordpress.org/images/1/18/Template_Hierarchy.png

share|improve this answer
Thanks! Okay so I've placed all that code above into archive.php but it doesn't show the month's posts it shows all posts no matter when it was posted. How can I alter the loop to just show the correct months' posts? I.e. a user clicks on February 2012 and they see only the posts made within Feb 2012. Any help would be appreciated :) –  egr103 Feb 1 '12 at 15:36

If it exists, usually archive.php. See the Template hierarchy.

share|improve this answer
Cheers for this but I'm having problems showing the posts for the correct month. At the moment that loop shows all posts. Are you able to shed any light on how I could alter the loop so that when a user clicks on, for example, Feb 2012 they only get all posts shown during Feb 2012? –  egr103 Feb 1 '12 at 15:39
WordPress will do that automatically... you don't need to alter the query, which it sounds like you are. Have a look at the TwentyEleven theme's archive.php. All you really need to do is loop through the posts and display them. –  Stephen Harris Feb 1 '12 at 15:54
I've had a play around with that archive.php file in twentyEleven, i've even copy pasted the code but even that doesn't work. I'm still getting all posts. I'd really appreciate it if you could lend a hand? Is my query above correct? –  egr103 Feb 1 '12 at 22:46

archive.php is the template file user will go to, when he clicks a month in the archive list.

share|improve this answer

Your Answer


