admin管理员组

文章数量:1294722

I'm making a custom post type that I want to use in the form of a plugin - all pretty straight forward.

However, I want the archive page for this post type to look slightly different in the content area - how would I achieve this without having to ask the end user to move files to their template directory?

I hope that makes sense, if not please ask me to clarify further - I've not really been able to find anything in the codex, but maybe I'm looking in the wrong place.

I'm making a custom post type that I want to use in the form of a plugin - all pretty straight forward.

However, I want the archive page for this post type to look slightly different in the content area - how would I achieve this without having to ask the end user to move files to their template directory?

I hope that makes sense, if not please ask me to clarify further - I've not really been able to find anything in the codex, but maybe I'm looking in the wrong place.

Share Improve this question asked Mar 15, 2013 at 11:12 user319940user319940 5762 gold badges5 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Use archive_template filter in your plugin to override archive templates for a given post type, for example, movies:

<?php
function get_movies_archive_template( $archive_template ) {
     if ( is_post_type_archive ( 'movies' ) ) {
          $archive_template = dirname( __FILE__ ) . '/templates/movies-archive-template.php';
     }
     return $archive_template;
}
add_filter( 'archive_template', 'get_movies_archive_template' ) ;

See archive_template in Codex.

本文标签: custom post typesHooking in to an archive page