WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#12974 closed enhancement (duplicate)

Add support to get_archive_template() for custom content types

Reported by: 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)

comment:1 mikeschinkel4 years ago

  • Cc mikeschinkel@… added

+1

comment:2 in reply to: ↑ description ; follow-up: markmcwilliams4 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?

comment:3 in reply to: ↑ 2 ; follow-up: mikeschinkel4 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.

comment:4 in reply to: ↑ 3 markmcwilliams4 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! :)

comment:5 follow-up: johnonolan4 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.

comment:6 in reply to: ↑ 5 markmcwilliams4 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?!

comment:7 scribu4 years ago

  • Cc scribu@… added

comment:8 azizur4 years ago

  • Cc prodevstudio+wordpress@… added

comment:9 nacin4 years ago

  • Milestone changed from Unassigned to 3.1

comment:10 maorb4 years ago

  • Cc maorb added

comment:11 mikeschinkel4 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?

comment:12 scribu4 years ago

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

comment:13 johnonolan4 years ago

Massive +1 on that suggestion Mike.

comment:14 kevinB4 years ago

  • Cc kevinB added

comment:15 darfuria4 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!

comment:16 epicalex4 years ago

  • Cc epicalex added

comment:17 follow-up: mattwiebe4 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.

comment:18 in reply to: ↑ 17 ; follow-up: mikeschinkel4 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?

comment:19 mikeschinkel4 years ago

  • Cc mikeschinkel@… added

comment:20 nacin4 years ago

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

comment:21 azizur4 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.

comment:22 follow-up: mikeschinkel4 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...

comment:23 in reply to: ↑ 22 ; follow-up: azizur4 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.

comment:24 in reply to: ↑ 23 mikeschinkel4 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.

comment:25 in reply to: ↑ 18 mattwiebe4 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.

comment:26 follow-up: nacin4 years ago

Duplicate of #13818?

comment:27 in reply to: ↑ 26 mikeschinkel4 years ago

Replying to nacin:

Duplicate of #13818?

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

comment:28 nacin4 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.

comment:29 nacin3 years ago

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