WordPress.org

Make WordPress Core

Opened 6 years ago

Last modified 5 months ago

#11725 new feature request

Add start and count attributes to gallery shortcode

Reported by: frymi Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.9.1
Component: Gallery Keywords: has-patch
Focuses: Cc:

Description

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

OR

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

Download all attachments as: .zip

Change History (38)

comment:1 @nacin6 years ago

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

comment:2 @frymi6 years ago

OK, try it.

comment:3 follow-up: @frymi6 years ago

SVN not work :-( ...

error: Commit failed, Server sent 403

comment:4 in reply to: ↑ 3 ; follow-up: @nacin6 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.)

comment:5 in reply to: ↑ 4 @frymi6 years ago

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

Thanx

comment:6 @frymi6 years ago

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

comment:7 @nacin6 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).

comment:8 @frymi6 years ago

nacin: Now updated files...

  • change arguments (start, count)
  • added comments

OK?

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

@frymi6 years ago

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

@frymi6 years ago

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

comment:9 @frymi6 years ago

How to delete attachment? (PHP files)

comment:10 @nacin6 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.

comment:11 @frymi6 years ago

nacin: Patch file is updated. Is it OK?

Thanx

comment:12 @nacin6 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.

comment:13 @frymi6 years ago

nacin: Patch updated. It is OK?

(Patch is tested and function)

@frymi6 years ago

Patch file for split-gallery in post (more)

comment:14 follow-up: @hakre6 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).

comment:15 @frymi6 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]

@nacin6 years ago

comment:16 in reply to: ↑ 14 @nacin6 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.

comment:17 @frymi6 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

yes?

comment:18 @frymi6 years ago

Line 776:

  1. must by add ... -1

(or)

  1. must by add ... >=

@nacin6 years ago

Fix bug in logic

comment:19 @nacin6 years ago

  • Keywords has-patch added

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

comment:20 @frymi6 years ago

nacin: Thanx.

comment:21 @nacin6 years ago

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

comment:22 @aaroncampbell4 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).

@aaroncampbell4 years ago

comment:23 @simbolo4 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.

comment:24 @mintindeed4 years ago

  • Cc gabriel.koen@… added

comment:25 @navjotjsingh4 years ago

  • Cc navjotjsingh@… added

@mintindeed3 years ago

comment:26 @mintindeed3 years ago

Updated patch against current version of trunk.

comment:27 @frymi2 years ago

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

comment:28 @buffler2 years ago

  • Cc jeremy.buller@… added

comment:29 @wonderboymusic13 months ago

#27058 was marked as a duplicate.

comment:30 @nboehr13 months 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.

comment:31 @SergeyBiryukov5 months ago

#32168 was marked as a duplicate.

Note: See TracTickets for help on using tickets.