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 have created a WordPress site, nothing out of ordinary, except that the posts - that are shown in the home page - are filtered by a fixed category, and place the filtering code in the home.php template of my theme. I use a custom permalink structure (something like site.com/posts/[post-slug-here]/).

Now I need to provide a section of the site that displays a list of all posts of the site, a global archive, with the URL site.com/archive/ and for this the output of wp_get_archives() will do just fine for what I need.

How to add the '/archive/' section to this site? I'll prefer not to create a "template" and having the user adding a page and assigning that template to the page in order to work. What I'm asking is for a solution that works as soon as the user activates the theme.

Thanks!

share|improve this question

1 Answer 1

You could use Custom Post Types which will keep users from selecting a custom template.

Here are a few links to help you get started:

Plug-ins:

For More Control you might use Custom Taxonomies (WordPress Codex Page):

The options mentioned above would require assigning existing posts that need to be added to the archives to the custom post types.

Another solution might be, adding a custom file that holds the code for the archives page. You could then use a conditional statement to call the file automatically if the posts meet the criteria you specify in the new file code. For example, you could create an archive called custom_archives.php (no custom template header required since you'll use get_template_part('custom_archives'); to call the file). Then in your index.php file or whichever is calling the posts you could use something like:

<?php if(is_category( 'commercials' ) ) {
  get_template_part('custom_archives'); 
?>

<?php 
} else { 
// your regular archives code...
} ?>

As you can see there is more than one option. It's hard to be more specific without knowing the full scope of your project, but one of the methods above should work. If you have questions I'll try to help.

share|improve this answer

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.