Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create a Wordpress theme, and I'm having a little difficulty with creating an easily accessible archives page.

First off, I'm not referring just to the standard archive.php in the template hierarchy. What I'm trying to do is make a separate page on the site that lists all posts (not sorted by tag/category/year) in a single, easily-accessible portion of the site by just going to /archive (e.g. www.example.com/archive)

I've read up on the Wordpress Codex that you can create a wordpress page using templates from PHP files, but I would really rather not go that route. If I could, I'd rather make a theme that already has the feature built in without the user having to manually do the work to create the page. Also, for some reason I never had a "template" dropdown section appear; go figure.

Does anyone have any ideas or suggestions for how to implement? Searching for an answer has been hard because most questions are about the template hierarchy or just using the page method.

I'm thinking that I should be looking into the add_rewrite_rule() function and rewriting the year with 'archive/'; the only issue with that is that it would limit by year.

share|improve this question
    
I've read up on the Wordpress Codex that you can create a wordpress page using templates from PHP files, but I would really rather not go that route. - out of curiosity: why do you not want to use a custom page template? –  Chip Bennett Feb 16 '13 at 12:50

1 Answer 1

up vote 0 down vote accepted

What I'm trying to do is make a separate page on the site that lists all posts (not sorted by tag/category/year) in a single, easily-accessible portion of the site by just going to /archive (e.g. www.example.com/archive)

The correct approach is, indeed, to create a custom page template, so that the user can create a static page (titled, e.g. Archives), and then assign the custom page template to that static page. The custom page template content would then be accessible via www.example.com/archives.

(Note: I would avoid any assumptions that involve static pages being named the same as WordPress core-reserved slugs, such as archive.)

If I could, I'd rather make a theme that already has the feature built in without the user having to manually do the work to create the page.

Themes should not create user content out-of-the-box. Themes should only define how user-generated content is presented. The user should create all content.

Also, for some reason I never had a "template" dropdown section appear; go figure.

Create this file, in your Theme's root directory: template-archives.php

Inside template-archives.php, add the following code:

/**
 * Template Name: Archives
 */

You will now see the "Template" drop down (with "Default" and "Archives" listed) in the Page Attributes meta box on the edit page screen.

Once you have verified that you see the drop down, congratulations! WordPress recognizes your custom page template, and you are then free to populate it with whatever content you want.

share|improve this answer
    
Thank you very much for your response, it worked perfectly! Originally I just didn't want to have to use the template pulldown because I would like to make the theme as easy as possible to use, but if it's the best method then I should do that. I never realized you needed the template comment for it to actually recognize it, that must have been my issue all along. Thanks a lot :D –  Bitwize Feb 16 '13 at 18:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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