WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/archive template

The "archive_template" filter can be used to load a custom template for a given archive. It will replace the template used whenever the "archive" template is called.

A plugin can register as a content filter with the code:

<?php add_filter( "archive_template", "plugin_function_name" ); ?>

Where "plugin_function_name" is the function WordPress should call when the content is being retrieved. Note that the filter function the plugin defines must return the a full path to a template file or the resulting page will be blank. The template file should have the same entries as the "archive.php" file has in the theme.

This is especially useful for plugins using the new Custom Post Types to load template files specific to your new post type.

Example with Custom Post Type

<?php
function get_custom_post_type_template( $archive_template ) {
     global $post;

     if ( is_post_type_archive ( 'my_post_type' ) ) {
          $archive_template = dirname( __FILE__ ) . '/post-type-template.php';
     }
     return $archive_template;
}

add_filter( 'archive_template', 'get_custom_post_type_template' ) ;
?>

The example code will load the template file "post-type-template.php" located in your plugins folder for any archive page that has the type of 'my_post_type' else uses default template.

Related

See also index of Function Reference and index of Template Tags.