Skip to main content
deleted 4 characters in body
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

Take a look at the Template Hierarchy section of the Codex that concerns Custom Post types.

  1. archive-{post_type}.php - If the post type were product, WordPress would look for archive-product.php.
  2. archive.php
  3. index.php

What you are describing is built in, down to the file naming pattern-- archive-cpt.php

To load the same template for all CPT archives use:

function not_post_archive_wpse_107931($template) {
  if (is_post_type_archive()) {
    $template = get_stylesheet_directory_uriget_stylesheet_directory().'/archive-cpt.php';
  }
  return $template;
}
add_filter('template_include','not_post_archive_wpse_107931');

That will hijack all CPT archives so I would be very careful with it. It could lead to great frustration if someone can't figure out why a CPT archive is not loading the expected template.

Barely tested. Possibly buggy. Caveat emptor. No refunds.

Take a look at the Template Hierarchy section of the Codex that concerns Custom Post types.

  1. archive-{post_type}.php - If the post type were product, WordPress would look for archive-product.php.
  2. archive.php
  3. index.php

What you are describing is built in, down to the file naming pattern-- archive-cpt.php

To load the same template for all CPT archives use:

function not_post_archive_wpse_107931($template) {
  if (is_post_type_archive()) {
    $template = get_stylesheet_directory_uri().'/archive-cpt.php';
  }
  return $template;
}
add_filter('template_include','not_post_archive_wpse_107931');

That will hijack all CPT archives so I would be very careful with it. It could lead to great frustration if someone can't figure out why a CPT archive is not loading the expected template.

Barely tested. Possibly buggy. Caveat emptor. No refunds.

Take a look at the Template Hierarchy section of the Codex that concerns Custom Post types.

  1. archive-{post_type}.php - If the post type were product, WordPress would look for archive-product.php.
  2. archive.php
  3. index.php

What you are describing is built in, down to the file naming pattern-- archive-cpt.php

To load the same template for all CPT archives use:

function not_post_archive_wpse_107931($template) {
  if (is_post_type_archive()) {
    $template = get_stylesheet_directory().'/archive-cpt.php';
  }
  return $template;
}
add_filter('template_include','not_post_archive_wpse_107931');

That will hijack all CPT archives so I would be very careful with it. It could lead to great frustration if someone can't figure out why a CPT archive is not loading the expected template.

Barely tested. Possibly buggy. Caveat emptor. No refunds.

added 522 characters in body
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

Take a look at the [Template Hierarchy section of the Codex that concerns Custom Post types][1]Template Hierarchy section of the Codex that concerns Custom Post types.

  1. archive-{post_type}.php - If the post type were product, WordPress would look for archive-product.php.
  2. archive.php
  3. index.php

What you are describing is built in, down to the file naming pattern-- archive-cpt.php [1]

To load the same template for all CPT archives use: http://codex.wordpress.org/Template_Hierarchy#Custom_Post_Types_display

function not_post_archive_wpse_107931($template) {
  if (is_post_type_archive()) {
    $template = get_stylesheet_directory_uri().'/archive-cpt.php';
  }
  return $template;
}
add_filter('template_include','not_post_archive_wpse_107931');

That will hijack all CPT archives so I would be very careful with it. It could lead to great frustration if someone can't figure out why a CPT archive is not loading the expected template.

Barely tested. Possibly buggy. Caveat emptor. No refunds.

Take a look at the [Template Hierarchy section of the Codex that concerns Custom Post types][1].

  1. archive-{post_type}.php - If the post type were product, WordPress would look for archive-product.php.
  2. archive.php
  3. index.php

What you are describing is built in, down to the file naming pattern-- archive-cpt.php [1]: http://codex.wordpress.org/Template_Hierarchy#Custom_Post_Types_display

Take a look at the Template Hierarchy section of the Codex that concerns Custom Post types.

  1. archive-{post_type}.php - If the post type were product, WordPress would look for archive-product.php.
  2. archive.php
  3. index.php

What you are describing is built in, down to the file naming pattern-- archive-cpt.php

To load the same template for all CPT archives use:

function not_post_archive_wpse_107931($template) {
  if (is_post_type_archive()) {
    $template = get_stylesheet_directory_uri().'/archive-cpt.php';
  }
  return $template;
}
add_filter('template_include','not_post_archive_wpse_107931');

That will hijack all CPT archives so I would be very careful with it. It could lead to great frustration if someone can't figure out why a CPT archive is not loading the expected template.

Barely tested. Possibly buggy. Caveat emptor. No refunds.

Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

Take a look at the [Template Hierarchy section of the Codex that concerns Custom Post types][1].

  1. archive-{post_type}.php - If the post type were product, WordPress would look for archive-product.php.
  2. archive.php
  3. index.php

What you are describing is built in, down to the file naming pattern-- archive-cpt.php [1]: http://codex.wordpress.org/Template_Hierarchy#Custom_Post_Types_display