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've (I think) an interesting problem here. What I want to do is create a global archive page, with everything on it. Dates, authors, categories etc all on one page.

I have a child theme, with TwentyTwelve as the parent. Inside TwentyTwelve there exists archive.php, category.php, tag.php, author.php etc., basically all faceted archive templates split up individually.

In my child theme what I want to do is to create an archive.php template, and have that overwrite all of the parents templates.

I understand creating archive.php in the child will overwrite the parents archive.php, but before it checks for archive.php it will check for category.php, and use that template from TwentyTwelve before hitting archive.php in my child theme. Same for all other templates as per the template hierarchy.

I know of at least 2 ways to fix this:

  1. Delete category.php, tag.php etc from TwentyTwelve. (Not the best, as any update will restore those files)
  2. Re-create tag.php, category.php, etc in my child theme and copy/paste my layout for each one into each template file. (Better, but lots of template files just makes for a messy directory.)

I'm wondering if there is something I could drop in functions.php to overwrite the hierarchy, and force WP to use my child archive.php for all archive pages.

Ideas?

Regards, Dave

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This is minimally tested-- nearly untested really-- but:

function force_archive_php_wpse_88824() {
  if (is_main_query() && is_archive()) {
    include (get_stylesheet_directory().'/archive.php');
    exit;
  }
}
add_action('template_redirect','force_archive_php_wpse_88824');

You are interrupting the template load process and forcing a file of your choice to be used.

Reference

http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect http://codex.wordpress.org/Function_Reference/get_stylesheet_directory

share|improve this answer
    
Perfect. Thanks. :) –  davebowker Feb 28 '13 at 15:32
add comment

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.