0

I am looking to create a page in Wordpress to output links to all of our posts from every month since we launched the blog. I have seen the archive.php template file in Wordpress, but this seems to overwrite a lot of other pages too (search results, author results, etc.)

So my plan is to create a single page similar to this archives page example. I was going to write a separate function solely for this page in my functions.php file, then use a shortcode to call out the info. Is this the best approach, or could I be going about this another way? Would appreciate any help on the topic :)

1 Answer 1

1

I would suggest taking a look at the Template Hierarchy structure to fully understand WHY archive.php overwrites certain pages (although it shouldn't overwrite search results)

If you wanted to go a custom template direction (might be the best way) I would do something like this

create a monthly-arcive.php file and paste the following (you can name it whatever)

/**
 * Template Name: Monthly Archive
 */
  //get the header
 get_header();

//normal WordPress loop 
if ( have_posts() ) : while ( have_posts() ) : the_post(); 
    the_content();
endwhile; 
endif; ?>

//show the archive list
<?php wp_get_archives('type=monthly'); ?>

//get footer
<?php get_footer(); ?>

Then create a new page and select "Monthly Archive as its template and you should be all set.

Things to note: You will need to style the custom template to match your other pages you may even want to start out by making a copy of another page. You should also look at wp_get_archive() in the Codex for more examples.

Hopefully that helps.

1
  • yeah this was great I really appreciate your response! I think this is the best way to go about things. I'll pop back if I have problems but your example is practically dumb-proof
    – Jake
    Commented Sep 25, 2011 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.