0

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!

1 Answer 1

0

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.

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.