Make WordPress Core

Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#12974 closed enhancement (duplicate)

Add support to get_archive_template() for custom content types

Reported by: johnonolan's profile johnonolan Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

Relevant to #12105

It would be great if custom content types could have their own category page templates.

Why? Primarily because if I have a custom content type, then I want people to be able to browse that content type, and I don't want them to browse the content type with the same styling and format as normal blog entries.

For example if I have a custom content type of "books", then I want a category page for books with a loop that returns all of my "books" in a custom format.

Continuing with this example, if I write a post called "A Book" then the slug becomes example.com/books/a-book/ however /example.com/books/ returns a 404. This is where I'd like to see archive-post_type.php kick in.

The new approach:

  • archive-post_type-slug.php
  • archive-post_type-id.php
  • archive-post_type.php
  • archive.php


This seems like a fairly obvious one to me (in place of hacking around with pages and custom-page-templates)

Change History (29)

#1 @mikeschinkel
15 years ago

  • Cc mikeschinkel@… added

+1

#2 in reply to: ↑ description ; follow-up: @markmcwilliams
15 years ago

Replying to johnonolan:

Continuing with this example, if I write a post called "A Book" then the slug becomes example.com/books/a-book/ however /example.com/books/ returns a 404. This is where I'd like to see archive-post_type.php kick in.

This seems like a fairly obvious one to me (in place of hacking around with pages and custom-page-templates)

I somehow feel like you'll receive the same answer as I did John, with regards to my 'Taxonomy Thing' I spoke about which I'm sure plenty of people read, I know I talked to you about it! Again it'll be down to the WordPress Rewrite System, oh hang on, any alarm bells ringing here?

#3 in reply to: ↑ 2 ; follow-up: @mikeschinkel
15 years ago

Replying to markmcwilliams:

I somehow feel like you'll receive the same answer as I did John, with regards to my 'Taxonomy Thing' I spoke about which I'm sure plenty of people read, I know I talked to you about it! Again it'll be down to the WordPress Rewrite System, oh hang on, any alarm bells ringing here?

Do you have a link to that discussion? I'd like to try to address any concerns that were raised in it on this ticket: #12935.

#4 in reply to: ↑ 3 @markmcwilliams
15 years ago

Replying to mikeschinkel:

Do you have a link to that discussion? I'd like to try to address any concerns that were raised in it on this ticket: #12935.

Yup, just visit http://lists.automattic.com/pipermail/wp-hackers/2010-February/030333.html and there are 75+ replies throughout the thread to read. I know a number of other people who expressed their interest, and spoke to me in various other places other than that discussion, I'll try point them in this/that direction and let them weigh in too! :)

#5 follow-up: @johnonolan
15 years ago

Let's chill on that old argument as it's not entirely relevant to this and I'd like to keep this ticket on topic.

#6 in reply to: ↑ 5 @markmcwilliams
15 years ago

Replying to johnonolan:

Let's chill on that old argument as it's not entirely relevant to this and I'd like to keep this ticket on topic.

Umm, I'm just someone with a loud mouth, and when I have something to say I'll jusy say it, so no offence here John! Ultimately this comes down to the way the WordPress Rewrite System works, there's no way about it! (Correct me if I'm wrong?)

Post Types, or Taxonomies, that all have the /baseterm/ then /whatever/ after, resulting in /books/professional-wordpress/ or /books/smashing-wordpress/ will always have the /baseterm/ 404'ing out on you until something is done...! It's simply there to point you in the right direction, not that I agree with the way that works in the slightest!

I can see you point John, don't get me wrong, but this doesn't just apply to Post Types, the Rewrite Rules are to blame (IMO) here! But hey, if I'm straying off-topic, then so be it, I find it amusing to see you're not being shot at and told to post on the WP-Hackers Mailing List, I know I was, with something basically the same ... no sour grapes though! ;)

If you want me, I'll be lurking in the background somewhere?!

#7 @scribu
14 years ago

  • Cc scribu@… added

#8 @azizur
14 years ago

  • Cc prodevstudio+wordpress@… added

#9 @nacin
14 years ago

  • Milestone changed from Unassigned to 3.1

#10 @maorb
14 years ago

  • Cc maorb added

#11 @mikeschinkel
14 years ago

Reviewing template-loader.php yesterday trying to find where to "hook" it I was just feeling the need for exactly this same thing.

However, can I propose we consider a different name from "archive?" I think that's a legacy blog term that really doesn't relate to custom post types, in general. For example if I have a site about movies and I create a "movie" and "actor" custom post types, do archive-movie.php and archive-actor.php make any contextual sense?

I don't know the best term, but here as some to consider:

  • many-{post_type}.php - i.e. "many" vs. "single?"
  • list-{post_type}.php - i.e. archives are lists of posts
  • loop-{post_type}.php - i.e. WordPress loves it some Loops
  • collection-{post_type}.php - i.e. archives are a collection of posts
  • other?

Seriously, wouldn't any of those be better than archive?

#12 @scribu
14 years ago

I would go with list-{post_type}.php.

#13 @johnonolan
14 years ago

Massive +1 on that suggestion Mike.

#14 @kevinB
14 years ago

  • Cc kevinB added

#15 @darfuria
14 years ago

I agree. It seems ridiculous to have /post-type/single and not have a browsable archive of all single items within that post type at /post-type.

type.php, type-id.php and type-slug.php are certainly required. I can't believe this didn't make it into 3.0!

#16 @epicalex
14 years ago

  • Cc epicalex added

#17 follow-up: @mattwiebe
14 years ago

  • Cc mattwiebe added

I tackled just this problem with my Smarter Custom Post Types, so just as a reference to something that's proven moderately popular:

  1. post_type/index.php - landing page/archive template
  2. post_type/single.php - template for single post

It's not a complete solution by any means, but just adding to the mix. I think the key thing for custom post types is to favor using subdirectories rather than filling up the theme root any more.

#18 in reply to: ↑ 17 ; follow-up: @mikeschinkel
14 years ago

  • Cc mikeschinkel@… removed

Replying to mattwiebe:

It's not a complete solution by any means, but just adding to the mix. I think the key thing for custom post types is to favor using subdirectories rather than filling up the theme root any more.

My first reaction is a -1 to subdirectories. I might be convinced otherwise but I think requiring subdirectories for the simple case can make something seem much less approachable for the new users and thus much harder than it really need to be on the low-end. I'm reminded of Ruby on Rails.

Maybe what would work well would be having subdirectories as one of the more specific options in the hierarchy, i.e. if a site only needs one or two custom post types then just put them all in the main theme directory. OTOH, if the themer wants the complexity of subdirectories because they are just dealing with too many files then they can reorganize and WordPress will give priority to files in the subdirectories.

So, best of both worlds; if you need tools to manage complexity you get them but they are not required for the simple case?

#19 @mikeschinkel
14 years ago

  • Cc mikeschinkel@… added

#20 @nacin
14 years ago

If we do a subdirectory route I imagine it would come out of #12877, not this ticket.

#21 @azizur
14 years ago

I am in support of sub directories. I am working on a project that has over 5 custom post types. Having sub directories means my themes will be a lot more organised.

It would be nice if I can place a sidebar or search form (post_type specific) or other parts and they are given priority for specific post_type.

#22 follow-up: @mikeschinkel
14 years ago

FWIW *anyone* can implement subdirectories on their own. The code to set up a template hierarchy is almost trivial. So no need to wait for WordPress if you need it now...

#23 in reply to: ↑ 22 ; follow-up: @azizur
14 years ago

Replying to mikeschinkel:

FWIW *anyone* can implement subdirectories on their own. The code to set up a template hierarchy is almost trivial. So no need to wait for WordPress if you need it now...

I am already doing this. I hope this would not break the site when client upgrade wordpress later on.

#24 in reply to: ↑ 23 @mikeschinkel
14 years ago

Replying to azizur:

I am already doing this. I hope this would not break the site when client upgrade wordpress later on.

It shouldn't unless you are using very generic names for subdirs and WordPress chooses to use the same names for subdirs, etc. Do something unlike what WordPress would do and you'll almost certainly be safe.

#25 in reply to: ↑ 18 @mattwiebe
14 years ago

Replying to mikeschinkel:

Maybe what would work well would be having subdirectories as one of the more specific options in the hierarchy, i.e. if a site only needs one or two custom post types then just put them all in the main theme directory. OTOH, if the themer wants the complexity of subdirectories because they are just dealing with too many files then they can reorganize and WordPress will give priority to files in the subdirectories.

So, best of both worlds; if you need tools to manage complexity you get them but they are not required for the simple case?

Exactly what I'd advocate. It's actually what my current code is doing, I just failed to mention that part. Just like the existing WP template hierarchy, from specific to general.

#26 follow-up: @nacin
14 years ago

Duplicate of #13818?

#27 in reply to: ↑ 26 @mikeschinkel
14 years ago

Replying to nacin:

Duplicate of #13818?

I think it would be the other way around; 12974 came first. :-)

#28 @nacin
14 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

True, but that one is already blessed for 3.1, and John won't mind.

Patches still welcome on the other ticket.

#29 @nacin
14 years ago

  • Milestone Awaiting Triage deleted
Note: See TracTickets for help on using tickets.