Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#22907 closed defect (bug) (fixed)

Twenty Eleven: Gallery thumbnail missing in some cases

Reported by: obenland's profile obenland Owned by: lancewillett's profile 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 11 years ago.
22907.1.diff (1.6 KB) - added by obenland 11 years ago.
22907.2.diff (3.5 KB) - added by lancewillett 11 years ago.
Move to function, provide fallback for missing IDs
22907.2.2.diff (3.4 KB) - added by lancewillett 11 years ago.
22907.3.diff (647 bytes) - added by kovshenin 11 years ago.

Download all attachments as: .zip

Change History (17)

@obenland
11 years ago

#1 @lancewillett
11 years 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.

#2 @nacin
11 years ago

  • Milestone changed from Awaiting Review to 3.6

See #22960 for a core function.

@obenland
11 years ago

#3 @obenland
11 years ago

Refreshed patch to provide forward compat with 3.6

#4 @lancewillett
11 years 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?

#5 @lancewillett
11 years 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. This is OK.
Last edited 11 years ago by lancewillett (previous) (diff)

#6 @lancewillett
11 years 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().

@lancewillett
11 years ago

Move to function, provide fallback for missing IDs

#7 @lancewillett
11 years 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).

#8 @lancewillett
11 years 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.

#9 @lancewillett
11 years ago

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

#10 @lancewillett
11 years 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.

@kovshenin
11 years ago

#11 @kovshenin
11 years 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.

#12 @lancewillett
11 years 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.