Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#33017 reopened defect (bug)

Images displayed with page.php instead of index.php

Reported by: creon's profile creon Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords: needs-patch 2nd-opinion needs-unit-tests
Focuses: template Cc:


I am developing a theme and currently do not have an attachment.php or a single.php. When I insert an unattached image into a post and select "Link to: Attachment Page", I expect the image to be displayed with index.php according to the template hierarchy However, the attachment page is displayed with the page.php tempalte instead, and the URL is under my static front page.

The issue does not show up with images attached to the post.

Attachments (1)

Screenshot 2016-10-12 16.53.28.png (287.4 KB) - added by implenton 8 years ago.
Query Monitor

Download all attachments as: .zip

Change History (7)

#1 @johnjamesjacoby
9 years ago

  • Keywords reporter-feedback added

Hi creon. Congratulations on filing your first bug report!

Are you able to test this without having a static front-page set, and report back which template is used then? Can you confirm there aren't any other plugins or theme code that might be causing this?

One thing I would test myself, but might be a bit unorthodox for some, is to activate a default WordPress theme but delete a few of the files out of it that you mentioned above to recreate those conditions, but in a trusted theme rather than a new one. That would help rule out anything that isn't vanilla, if that makes sense.

#2 @creon
9 years ago

  • Keywords reporter-feedback removed

It looks like there is no difference when I switch to a 'Latest Posts' front page and back to a static one. However, it turns out the image is actually attached. I was not aware that when you insert an unattached image into a post, the post the image was inserted into becomes the image's new parent (at least, looking at the 'post_parent' property via the 'Debug This' plugin). The image I thought was unattached was actually attached to a page.

When I deactivate all plugins and switch to a copy of twentyfifteen 1.2 (with image.php and single.php deleted), the behavior is the same.

In both scenarios, there is no problem when the image is attached to a post, it is just when the image is attached to a page that the 'attachment page' uses page.php. Looking back at the template hierarchy, I suppose it is not 'unexpected behavior', but I thought attachments would get the same template logic regardless of their post_parent post type.

#3 @wonderboymusic
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I can't reproduce this - I tried many combinations of templates. Thanks for the ticket, though.

8 years ago

Query Monitor

#4 @implenton
8 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened
  • Summary changed from Unattached images displayed with page.php instead of index.php to Images displayed with page.php instead of index.php
  • Version 4.2.2 deleted

@wonderboymusic I can reproduse this.

I am using for content the Theme Unit Test

After importing the XML, URL to visit: /about/clearing-floats/spectacles-2/

Permalink Settings: "Month and name"

Query Monitor debug info attached.

This ticket was mentioned in Slack in #core by meszarosrob. View the logs.

8 years ago

#6 @johnbillion
8 years ago

  • Keywords needs-patch 2nd-opinion needs-unit-tests added
  • Milestone set to Awaiting Review

Confirmed. When viewing an attachment uploaded to a Page, is_page() is true, causing the template hierarchy to include templates for page.php etc, too. The same does not occur when viewing an attachment uploaded to a Post.

Changing this might cause a break in expected behaviour. Needs good test coverage and a patch.

Note: See TracTickets for help on using tickets.