WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 23 months ago

#12799 new feature request

Allow gallery shortcode to accept a maximum number of items

Reported by: dtorbert Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.9.2
Component: Gallery Keywords: gallery maximum has-patch
Focuses: Cc:

Description

A "would be nice" feature of the gallery would be to allow for a maximum number of items to be displayed.

The main use of this feature would be to allow a page to show a "preview" of some of the images contained within one or more subpages, eg:

  • Some event

[gallery link="file" columns="4" orderby="rand" maximum="4" id="164"]

  • Some other event

[gallery link="file" columns="4" orderby="rand" maximum="4" id="200"]

Attachments (2)

gallery shortcode replacement.txt (4.4 KB) - added by dtorbert 4 years ago.
Suggested replacement for gallery_shortcode()
12799.diff (2.4 KB) - added by jamescollins 23 months ago.

Download all attachments as: .zip

Change History (6)

dtorbert4 years ago

Suggested replacement for gallery_shortcode()

comment:1 nacin4 years ago

  • Milestone changed from Awaiting Review to Future Release

comment:2 BinaryMoon23 months ago

Hi - I have a use case for this - specifically for gallery custom post types where I want to display a subset of the gallery on the archive/ homepage. As such - is there an update for when this might happen as I think it would be really useful.

jamescollins23 months ago

comment:3 jamescollins23 months ago

  • Keywords has-patch added

12799.diff adds an optional numberimages="" parameter to the [gallery] shortcode.

This parameter is named similarly to the numberposts attribute in get_posts().

If the numberimages parameter is set to a number greater than zero, then it controls the maximum number of images displayed by the [gallery] shortcode.

Examples:

[gallery link="file" columns="4" orderby="rand" numberimages="4" id="256"]
[gallery link="file" columns="4" orderby="rand" numberimages="4" include="263,264,261,260,259"]

In both cases, only 4 images (at most) will be displayed.

The code on line 836-839 is only necessary because in get_posts(), when specifying include="", the numberposts parameter is ignored (it's set to match the number if items in include="").

comment:4 BinaryMoon23 months ago

that looks perfect for my needs - does this diff mean that it will be added to core, or is it just a proposal for inclusion (I'm new to Trac - don't know how it works)?

Note: See TracTickets for help on using tickets.