We’re building a plugin that displays posts, and we also want to display the image gallery when it is used in a post. However, we need to limit the number of photos displayed? Is that possible?
Leave a Reply
You must be logged in to post a comment.
We’re building a plugin that displays posts, and we also want to display the image gallery when it is used in a post. However, we need to limit the number of photos displayed? Is that possible?
You must be logged in to post a comment.
There’s two ways you can go about this, but both involve creating a function that does pretty much the same as the existing gallery shortcode function…
You can either..
post_gallery
and manipulate the incoming data(you can use the gallery shortcode function as a base for the filter if necessary)I did something similar in this thread, and i’m only referring to it because i’m going to take the same approach for the example that follows.
Example filter for the gallery shortcode
Modify that function to impose whatever restrictions you like(it’s just a base)..
You can find the hook i’m using in
wp-includes/media.php
inside the gallery shortcode callback function(see line 763).http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/media.php#L745
Hope that helps.. 🙂
You can specify the number of images per gallery. This can be configured via the gallery tab in the media thickbox in the post editor. After you have already inserted the gallery, I think you can edit that by editing the gallery in the visual editor.