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'm currently working on a theme that makes heavy use of custom post types to structure the content. To display a lot of the content I am using the respective archive-$posttype.php but this seems in many ways more cumbersome than using a page template.

When using a page template to display the archive I can easily set or modify:

  • a descriptive title
  • a description
  • the slug
  • a header image for the page
  • meta boxes for whatever added piece of information I might need
  • the page can be easily integrated into the menu

Unless I'm mistaken none of this can be done for the archive without modifying the template files. Theme settings might help with some of that but I haven't dealt with them yet and it's certainly more difficult than simply using a page template.

The only advantage I'm seeing is less clutter when selecting a page template and maybe less hassle with the link structure when display single custom posts. There is probably a performance impact but I have no clue how large.

Considering all that why should I use the custom post archive?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

When you use a custom page template you run 2 sql queries to display the page: the first is ran by WordPress to get the page, the second is ran inside the page template file using secondary queries (new WP_Query).

A direct consequence of that (besides the performance impact) is that intercept the main query and, just for example, do stuff on pre_get_posts based on the query arguments is very easy when you use archives file (the query that get posts is the main), when you use a page template modify the query you run inside the template can be very hard, and possibly only way is using another template...

After that, using a post type archive users don't need to set anything on backend, just add CPT posts and ther are shown using archive-$posttype.php.

When you use a page template users have to:

  • create a page
  • assign the page template

If your theme going to be sold or shared in some way, people that have to use have to do those 2 tasks for every cpt, using the archive-$posttype.php method, they don't need to do anything.

Another thing on behalf of archive files is that if other developers see your theme files, and see a archive-foo.php file, immediately undestand (without open any file) that archive-foo.php is used to display posts of 'foo' CPT, using page templates they need to read the code or... guess.

However, yes, using a page template can be useful for something of the things that you listed and probably other.

So there is no a general rule "one is better than the other": if you absolutely need some deep configuration for archives, then page template are useful (being aware of what are the consequences), but for some CPTs where you don't need that configurations, the archive files are perfectly fine.

share|improve this answer
    
Thanks for all the info. Seems for my use cases a page template would usually be best but good to know all the possibilities. –  Seraphithan Apr 2 at 14:46

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.