Make WordPress Core

Opened 12 years ago

Last modified 2 years ago

#11725 new feature request

Add start and count attributes to gallery shortcode

Reported by: 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 12 years ago.
Modify file media.php for split-show images from gallery
media.3.php (45.3 KB) - added by frymi 12 years ago.
Modify file media.php for split-show images from gallery
media.patch (1.2 KB) - added by frymi 12 years ago.
Patch file for split-gallery in post (more)
11725.diff (1.3 KB) - added by nacin 12 years ago.
11725.2.diff (1.3 KB) - added by nacin 12 years ago.
Fix bug in logic
11725.3.diff (2.3 KB) - added by aaroncampbell 11 years ago.
11725.4.patch (2.1 KB) - added by mintindeed 9 years ago.

Download all attachments as: .zip

Change History (38)

#1 @nacin
12 years ago

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

#2 @frymi
12 years ago

OK, try it.

#3 follow-up: @frymi
12 years ago

SVN not work :-( ...

error: Commit failed, Server sent 403

#4 in reply to: ↑ 3 ; follow-up: @nacin
12 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
12 years ago

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


#6 @frymi
12 years ago

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

#7 @nacin
12 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 http://codex.wordpress.org/WordPress_Coding_Standards).

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 http://codex.wordpress.org/Reporting_Bugs#Trac_Keywords).

#8 @frymi
12 years ago

nacin: Now updated files...

  • change arguments (start, count)
  • added comments


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

12 years ago

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

12 years ago

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

#9 @frymi
12 years ago

How to delete attachment? (PHP files)

#10 @nacin
12 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
12 years ago

nacin: Patch file is updated. Is it OK?


#12 @nacin
12 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
12 years ago

nacin: Patch updated. It is OK?

(Patch is tested and function)

12 years ago

Patch file for split-gallery in post (more)

#14 follow-up: @hakre
12 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
12 years ago

For example: this patch is used here http://www.predskolaci.cz/?cat=24

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]

12 years ago

#16 in reply to: ↑ 14 @nacin
12 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
12 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
12 years ago

Line 776:

  1. must by add ... -1


  1. must by add ... >=

12 years ago

Fix bug in logic

#19 @nacin
12 years ago

  • Keywords has-patch added

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

#20 @frymi
12 years ago

nacin: Thanx.

#21 @nacin
12 years ago

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

#22 @aaroncampbell
11 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
10 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
10 years ago

  • Cc gabriel.koen@… added

#25 @navjotjsingh
10 years ago

  • Cc navjotjsingh@… added

9 years ago

#26 @mintindeed
9 years ago

Updated patch against current version of trunk.

#27 @frymi
8 years ago

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

#28 @buffler
8 years ago

  • Cc jeremy.buller@… added

#29 @wonderboymusic
7 years ago

#27058 was marked as a duplicate.

#30 @nboehr
7 years ago

Because it seems that this functionality will never make it into the Wordpress Core, I created a plugin that does something similar: https://wordpress.org/plugins/limit-parameter-for-gallery-shortcode/

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

#31 @SergeyBiryukov
6 years ago

#32168 was marked as a duplicate.

Note: See TracTickets for help on using tickets.