Support » Developing with WordPress » Custom Attachment page for Custom Post Type

  • Michael D

    (@michael-divine)


    I’m not sure if this is possible. It seemed to me that it would be with this:
    single-attachment-{slug}.php

    But, for instance, if my custom post type is FFF then the template page for that is single-FFF.php. When I click an image in that, I’d like it if it called up a template page with the same slug like attachment-FFF.php or single-attachment-FFF.php.

    As far as I can tell, this isn’t possible, unless I’m missing something. So… am I missing something?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Have you looked at the Template Hierarchy?
    First, slugs are lower case. You can have single-fff.php for your fff post type, and even single-fff-xyz.php for the specific xyz post.
    But attachments are a separate post type (internal), so the template names are for the mime types of the attachment. It has nothing to do with the post type that it is attached to.
    You could conceivably filter the template used, with template_include, but you would have to supply the logic of falling back to the appropriate one.
    Do you have a special attachment type? My theme adds information to image attachment pages by using the ‘prepend_attachment’ filter.

    Thread Starter Michael D

    (@michael-divine)

    Thanks. Yes, I’m using lower case otherwise – that was just the example.

    I did look through the template hierarchy but the
    I was just hoping to call attachments of a certain category/posttype/something else/

    For instance – I have a custom post type that is called Gallery and in it is a gallery of images that link to a attachment pages from the image. Clicking the image loads a lightbox style iframe so I can have a bunch of custom field info in with it. So the actual attachment.php template is very pared down. This means it can’t be used for anything else ever. I don’t know that I will use it for anything else (i rarely do) but I was seeing if it was an option as it’s nice to keep things orderly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Attachment page for Custom Post Type’ is closed to new replies.