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 Answer 1

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"]
2
  • 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 Commented Feb 3, 2015 at 14:31
  • Please check out the updated the answer @Bizcochoman
    – birgire
    Commented Feb 4, 2015 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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