0

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

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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