Make WordPress Core

Opened 15 years ago

Closed 2 years ago

#11725 closed feature request (wontfix)

Add start and count attributes to gallery shortcode

Reported by: frymi's profile frymi Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.9.1
Component: Gallery Keywords: has-patch
Focuses: Cc:


Add shotcodes COUNT for views full gallery after click on MORE. Home

Modify files ./wp-includes/media.php
Lines 699 (add COUNT => '-1')
Lines 767-798 (add ForEach ... )

Use in WP:

[gallery] ... show standard gallery


[gallery count=3] ... show images 1-3

  • more -

[gallery count=3+] ... show images 4-n

Attachments (7)

media.2.php (45.3 KB) - added by frymi 15 years ago.
Modify file media.php for split-show images from gallery
media.3.php (45.3 KB) - added by frymi 15 years ago.
Modify file media.php for split-show images from gallery
media.patch (1.2 KB) - added by frymi 15 years ago.
Patch file for split-gallery in post (more)
11725.diff (1.3 KB) - added by nacin 15 years ago.
11725.2.diff (1.3 KB) - added by nacin 15 years ago.
Fix bug in logic
11725.3.diff (2.3 KB) - added by aaroncampbell 13 years ago.
11725.4.patch (2.1 KB) - added by mintindeed 12 years ago.

Download all attachments as: .zip

Change History (39)

#1 @nacin
15 years ago

  • Component changed from Media to Gallery
  • Keywords needs-patch added; gallery photo images removed

#2 @frymi
15 years ago

OK, try it.

#3 follow-up: @frymi
15 years ago

SVN not work :-( ...

error: Commit failed, Server sent 403

#4 in reply to: ↑ 3 ; follow-up: @nacin
15 years ago

Replying to frymi:

SVN not work :-( ...

error: Commit failed, Server sent 403

You need to generate a patch and attach it here. If accepted for WordPress, a core developer (there are five of them) will then commit the patch. (403 is an unauthorized error code.)

#5 in reply to: ↑ 4 @frymi
15 years ago

media.php is "attached" - is it OK?


#6 @frymi
15 years ago

  • Keywords gallery post split gallery added; needs-patch removed

#7 @nacin
15 years ago

  • Keywords needs-patch added; gallery post split gallery removed

I think count = -1 and the "+" are both hacks. Just a thought: If this is to make it in core, I think a patch should add two arguments: count, and start. Thus, you'd do [gallery count="3"] (start = 1 implied) and [gallery start="4"] (count = all implied) and [gallery count="2" start="5"] (the fifth and sixth images only).

Patch also broke some code conventions related to indenting (use tabs), use of comments (most of the ones you added aren't needed), and control structure whitespace (more at

We also can't just strip out that CSS without accounting for it elsewhere. That should be handled in another ticket (and there probably is one already).

Back to needs-patch. Also, the keywords you added are useless to our workflow here. (Somewhat incomplete list at

#8 @frymi
15 years ago

nacin: Now updated files...

  • change arguments (start, count)
  • added comments


PS: I am czech and dont speak english ;-)

15 years ago

Modify file media.php for split-show images from gallery

15 years ago

Modify file media.php for split-show images from gallery

#9 @frymi
15 years ago

How to delete attachment? (PHP files)

#10 @nacin
15 years ago

  • Summary changed from Views images (1-3 from gallery) in post, and other images show after click on MORE to Add start and count attributes to gallery shortcode

Don't worry about the extra attachments. Though we only are looking for patches, the full files aren't very useful.

I meant less comments, not more -- most code is self explanatory. The patch is still a mess, unfortunately. It isn't up to WordPress inclusion standards yet. You have issues with indentation and white space, the CSS needs to remain in there, etc.

#11 @frymi
15 years ago

nacin: Patch file is updated. Is it OK?


#12 @nacin
15 years ago

Lines 698-700 - commas should be after the array items, not before.

Comment on 760 isn't necessary (or should be intended and lowercased).

count() call on 762 should be lowercase.

We use
and &&, not OR and AND. (Not just for consistency, either -- they work differently,as PHP places them at different spots in operator precedence.)

The continue statement is fine for < $start, but if we've gone beyond $start + $count, we should break instead that way we don't keep running the loop when we don't need to.

Though I haven't tested it, the logic looks like it would work fine. I would probably sanitize $count early though, instead of making numerous casts and checks throughout. And $start isn't sanitized at all. We have a function absint() that could help.

#13 @frymi
15 years ago

nacin: Patch updated. It is OK?

(Patch is tested and function)

15 years ago

Patch file for split-gallery in post (more)

#14 follow-up: @hakre
15 years ago

Thanks for providing a patch and some code. I pretty much feel that this is more of hack than a pretty implementation - but your intentions are perfectly valid. If we provide such arguments I would like to see a gallery lookup function that returns the actual gallery images so that it can be used in other places as well, e.g. for other listings, gallery plugins and the like. Maybe a filter function which runs on $attachments can do the job as well, so there is no need to interfere with the foreach iteration.

If not, this looks pretty much like a plugin to me that can filter the galleries output. To better support it we can add more hooks (I ran over the problem that galleries output can not be properly manipulated if you do not do any advanced workarounds).

#15 @frymi
15 years ago

For example: this patch is used here

In open category > show images 1-3,1-6 [gallery count=3]
After click on post --more-- > show gallery, images 4-n [gallery start=4]

15 years ago

#16 in reply to: ↑ 14 @nacin
15 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Unassigned to Future Release

I added another patch that cleans up the logic and sanitization a bit.

I'm not sold that this is core material but I do find it useful, being able to break up a gallery across pages, a more tag, or paragraphs of text, etc.

has-patch, adding to future release for now.

#17 @frymi
15 years ago

  • Keywords has-patch removed

nacin: 11725.diff - not work right.

[gallery count=6] not views 1-6 img, but show 7 img!
[gallery start=4] is OK
Line 776 must by: $start + $count -1


#18 @frymi
15 years ago

Line 776:

  1. must by add ... -1


  1. must by add ... >=

15 years ago

Fix bug in logic

#19 @nacin
15 years ago

  • Keywords has-patch added

Didn't test it at first, and omitted an =

#20 @frymi
15 years ago

nacin: Thanx.

#21 @nacin
15 years ago

Cross-referencing #7958. I like "limit" over "count" that originated there, I think.

#22 @aaroncampbell
13 years ago

Maybe I'm missing what you guys are trying to accomplish here, but why doesn't the patch just pass start-1 as offset and count as numberposts to get_posts() and get_children()? I'm uploading a patch to show what I mean (although I didn't really test it).

#23 @simbolo
13 years ago

I personally like Aaron's solution as it is more flexible than a straight up limit clause. However, I would change the wording from count to limit as it makes more sense IMHO.

#24 @mintindeed
13 years ago

  • Cc gabriel.koen@… added

#25 @navjotjsingh
12 years ago

  • Cc navjotjsingh@… added

12 years ago

#26 @mintindeed
12 years ago

Updated patch against current version of trunk.

#27 @frymi
11 years ago

Please info that will be included in the new version of WordPress?

#28 @buffler
11 years ago

  • Cc jeremy.buller@… added

#29 @wonderboymusic
10 years ago

#27058 was marked as a duplicate.

#30 @nboehr
10 years ago

Because it seems that this functionality will never make it into the Wordpress Core, I created a plugin that does something similar:

It should be possible to integrate offset functionality pretty easy. I will happily accept a patch for this.

#31 @SergeyBiryukov
9 years ago

#32168 was marked as a duplicate.

#32 @desrosj
2 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

I'm going to close this one out.

There has been no interest shown in a decade, and I'm not really convinced this is a good addition to Core. It could get really confusing when using different orderby options and combining with an offset/start value, and I don't really understand the use case. I'm guessing the idea would be to have pagination, or link off to a full gallery page? But both seem like a poor user experience that would require some custom templates in a theme.

Additionally, 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.

Note: See TracTickets for help on using tickets.