0

I'm using Jetpack with Wordpress and creating a gallery. The thing is that I don't want all the images from that gallery to be shown, only the last 50 of them. Is there any solution to this using just the shortcode?

If not, is there any other solution?

Also, I have another doubt about the usage of galleries in Wordpress, is it possible to assign a name (or ID) to the gallery and call it in the code? For example

<?php echo do_shortcode("[gallery name='my_gallery']"); ?>

Thanks in advance!

1

If you want to display the attached image gallery, from another post, you can use:

[gallery id="123"]

where the custom id attribute is the post ID.

If you want limit the number of items in a gallery, there seems to be a plugin available on wordpress.org called Limit parameter for gallery shortcode (no affiliation). It uses the pre_get_posts filter to change the posts_per_page and offset attributes of the get_posts() or get_children() calls in the gallery shortcode callback.

Example:

[gallery id="4" limit="3" offset="1"]
  • This seems perfect. Also, is there any attribute to put in the shortcode for displaying a fixed number of images? For example, for just displaying the last 10 images – Bizcochoman Feb 3 '15 at 14:31
  • Please check out the updated the answer @Bizcochoman – birgire Feb 4 '15 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.