Opened 15 years ago
Last modified 14 months ago
#12799 new enhancement
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 |
Component: | Gallery | Keywords: | has-patch changes-requested close good-first-bug |
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 (6)
Change History (28)
#2
@
12 years 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.
#3
@
12 years 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="").
#4
follow-up:
↓ 5
@
12 years 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)?
#5
in reply to:
↑ 4
@
10 years ago
- Keywords dev-feedback needs-refresh added; gallery maximum has-patch removed
- Version changed from 2.9.2 to 2.9
Replying to BinaryMoon:
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)?
It means it's something we can merge into core, but not marked for inclusion (that's the milestone for the ticket)
Other devs: Do we want to support a max param, or do we want to relegate that to a plugin to support?
#6
@
9 years ago
- Keywords needs-docs added
I like the idea of having a maximum number of images to display. I could see a use case of this if someone is wanting to randomly cycle through a preset list of images.
I like this...I'll work on updating the patch. I think this will also need docs on the new option.
#7
@
9 years ago
- Keywords has-patch added; needs-refresh needs-docs removed
- Milestone changed from Future Release to 4.4
Woot! Below is the new patch. Tested on the nightly and it seems to be working like a charm now! After using it, I really like the addition. I think it could be useful. It's kinda cool refreshing the page and getting different random images.
I went with maxdisp
as the shortcode attribute for the sake of keeping it short and sweet. Also added docs to the shortcode listing.
Usage looks like the below shortcode:
[gallery include="8,7,6,5,4" maxdisp="2" orderby="rand"]
Would still like a lead dev to thumbs up this so leaving dev feedback.
Patch below!
#8
@
9 years ago
Nice - thanks :)
Not sure about maxdisp as the attribute name though. I'd imagine something like 'count' would be clearer?
To me maxdisp sounds very programmery (like a variable name) and I'm not sure the average user would understand it's use.
#9
@
9 years ago
Thanks.
It is something I needed on several websites. Both max and random. If used in widget and Users dont have access to widget managament better to use "post ID" than "include".
#10
@
9 years ago
Completely agree. It's the robot in me that decided on maxdisp
. I like count
much better. Also, this works just the same with ids=
as well.
[gallery ids="8,7,6,5,4" count="2" orderby="rand"]
Updated patch below!
This ticket was mentioned in Slack in #design by antpb. View the logs.
9 years ago
This ticket was mentioned in Slack in #design by antpb. View the logs.
9 years ago
#13
follow-up:
↓ 14
@
9 years ago
This looks great @dtorbert!
@antpb your most recent diff has a few spacing issues in the first phpdoc block (L1397) and then the array (L1448).
Also, I noticed a typo on L1476:
Necessary because in get_posts(), when specifying include="", the numberposts parameter is ignored (it's set to match the number if items in include="")`
I believe you meant number of items
.
#14
in reply to:
↑ 13
@
9 years ago
Replying to michaelbeil: Thanks! Good catch. I actually copied the line from a previous diff.
I went ahead and fixed the spacing issue as well. Patch to follow...
This looks great @dtorbert!
@antpb your most recent diff has a few spacing issues in the first phpdoc block (L1397) and then the array (L1448).
Also, I noticed a typo on L1476:
Necessary because in get_posts(), when specifying include="", the numberposts parameter is ignored (it's set to match the number if items in include="")`
I believe you meant
number of items
.
#16
in reply to:
↑ 12
@
9 years ago
Replying to slackbot:
This ticket was mentioned in Slack in #design by antpb. View the logs.
Having a UI for this by default does not make sense, though an unexposed shortcode attribute seems reasonable. See the discussion for more details.
This ticket was mentioned in Slack in #core by helen. View the logs.
9 years ago
#19
follow-up:
↓ 21
@
9 years ago
I'm not sure count
is the right name for the attribute either, even if that's what it's called in the code.
This ticket was mentioned in Slack in #core-editor by talldanwp. View the logs.
5 years ago
#21
in reply to:
↑ 19
@
2 years ago
- Keywords needs-refresh changes-requested close good-first-bug added; dev-feedback removed
- Milestone set to Future Release
With the introduction of the block editor and full site editing, shortcodes (though still supported) are no longer the recommended way to display a gallery.
With that in mind, I'm going to add a close
suggestion as a maybelater
. I won't close this out right now because I think it's a fair attribute to introduce, even in block editor times. If someone is interested in taking the time to create a new patch, this can be looked at. If there's no new activity in a few months, I'll return and close it out.
Because it has not received any attention in over 7 years, 12799-4.diff certainly will need a refresh.
Replying to helen:
I'm not sure
count
is the right name for the attribute either, even if that's what it's called in the code.
I also don't like count
as the attribute name. limit
feels like a more natural name to give this one.
This ticket was mentioned in PR #5530 on WordPress/wordpress-develop by Lymnik01.
14 months ago
#22
- Keywords needs-refresh removed
I renamed the shortcode parameter that limits the number of images shown by the schortcode to 'limit'.
Limiting the number of images should be possible for shortcodes using the include-parameter, exclude-parameter and for those that use neither. For that I combined some elements of the previous patch( 12799-2.diff ) with some elements of the one before that( 12799-4.diff ).
Trac ticket: https://core.trac.wordpress.org/ticket/12799
Suggested replacement for gallery_shortcode()