WordPress.org

Make WordPress Core

#22907 closed defect (bug) (fixed)

Twenty Eleven: Gallery thumbnail missing in some cases

Reported by: obenland Owned by: lancewillett
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.5
Component: Bundled Theme Keywords: has-patch
Focuses: Cc:

Description

With new Media came the possibility to create galleries from all uploaded pictures, not only the ones to a specific post. In the edge case that the gallery does not contain at least one image attachment that has the given post as a parent, the query for it comes up empty.

Additionally, as soon as there is one image in the gallerie that does not have the given post as a parent, the image count will be off.

Attachments (5)

22907.diff (1.4 KB) - added by obenland 16 months ago.
22907.1.diff (1.6 KB) - added by obenland 13 months ago.
22907.2.diff (3.5 KB) - added by lancewillett 13 months ago.
Move to function, provide fallback for missing IDs
22907.2.2.diff (3.4 KB) - added by lancewillett 13 months ago.
22907.3.diff (647 bytes) - added by kovshenin 12 months ago.

Download all attachments as: .zip

Change History (17)

obenland16 months ago

comment:1 lancewillett16 months ago

I think it'd be cool to make this a core function — moving all this code out of this one theme and into a function that *any* theme could use.

comment:2 nacin16 months ago

  • Milestone changed from Awaiting Review to 3.6

See #22960 for a core function.

obenland13 months ago

comment:3 obenland13 months ago

Refreshed patch to provide forward compat with 3.6

comment:4 lancewillett13 months ago

  • Keywords needs-testing added

@obenland -- what do you think about moving this to a function in functions.php instead? Shouldn't affect back compat.

What are the test cases we need to check, back to 3.3 or 3.4 -- create a gallery and insert it into a different post instead of the parent post?

comment:5 lancewillett13 months ago

Testing notes:

  • 3.6 trunk, gallery post format with just [gallery] shortcode is empty on index view (using the Theme Unit Test Data, it's the Post Format Test: Gallery post). Looks as expected on single view.
  • 3.5.1: using [gallery ids="619,618,617"] as test post content -- nothing is visible on index, but the Theme Unit Test post works fine on index. Single working as expected.
  • 3.4.2: no gallery content visible on index or view with [gallery ids="619,618,617"] as test post content -- both views are empty.
Version 0, edited 13 months ago by lancewillett (next)

comment:6 lancewillett13 months ago

So I figured out why the 3.5.1 and 3.6 cases don't work -- this solution depends on ids attribute being set in the shortcode.

If that's an OK assumption (since 3.5+ adding a gallery to content should add the IDs also) -- we can go with it.

Otherwise, we should catch that in the code -- if after checking with get_post_galleries() and the $images array is still empty -- go with the fallback that uses {get_posts().

lancewillett13 months ago

Move to function, provide fallback for missing IDs

comment:7 lancewillett13 months ago

.2 moves to functions.php to simplify the template file, and also provides the get_posts() call as a fallback even if 'get_post_gallery_images' exists (for the case it fails to get any IDs back).

comment:8 lancewillett13 months ago

  • Keywords needs-testing removed

Tested in 3.4.2, 3.5.1, and 3.6 trunk. Works now for both "bare" gallery shortcode with no attributes, and for shortcode with "ids" attributes.

lancewillett13 months ago

comment:9 lancewillett13 months ago

Patch updates comment block for accuracy for new function, and also returns only array value instead of mixed.

comment:10 lancewillett13 months ago

  • Owner set to lancewillett
  • Resolution set to fixed
  • Status changed from new to closed

In 23824:

Twenty Eleven: improve how gallery image IDs are retrieved for use in the Gallery post format template. Props to obenland for original patch, fixes #22907.

kovshenin12 months ago

comment:11 kovshenin12 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

[24093] introduced a new $html argument to get_post_galleries which defaults to true and breaks gallery counts (displays always 1 without a thumbnail). 22907.3.diff addresses this, and also changes the function we check in function_exists to the one that is actually used.

Same in Twenty Ten.

comment:12 lancewillett12 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 24194:

Twenty Eleven: call get_post_galleries() correctly now that it has new arguments, and use a more accurate function_exists call. Props kovshenin, closes #22907.

Note: See TracTickets for help on using tickets.