An example of what I’m looking to achieve is as follows;
I’ve built a template page running with a mildly modified wp gallery shortcode function (mainly with the linebreaks removed for a fluid theme) and using Jetpack carousel downstream.
What I’d like to do is list 4 images from the gallery atached to a post, then link (view the full gallery) to a page which contains larger thumbnails of the gallery items, which will then open (when clicked) to be viewed using Jetpack carousel.
I’m not interested in using NextGen or reinventing the wheel using a different image carousel.
Perhaps the simplest way to articulate the problem I’m trying to solve is as follows:
What I’m looking to do is;
- query post attachments as part of the main wordpress loop, but instead of returning the full list of attachments (as the_content does by default), I’d like to display just ‘four’ image attachments along with a ‘view more’ link (and a statement for how many images are available in the gallery).
- when ‘view more’ is clicked, this should release the remaining post attachments (which in my case could be as many as 50) as a list of thumbnails
- rather than automagically ‘reveal’ these on the same page, I would like to display these in a seperate gallery layout – without the rest of the post content.
The functionality sounds a lot like post_excerpt, but for image items rather than words of text.
The other issue I am conscious of is efficiency (in terms of database queries). Ideally it shouldn’t add any additional queries. It’s a fair assumption than when the main loop is executed and the post_content is retrieved, this including the image attachments should be kept available (until the query is reset), so I don’t want to retrieve four images for the main post page, then retrieve a further 46 images when displaying the full gallery – that would seem wasteful.
I have currently put together a template page which contains these gallery thumbnails, but upon further reflection this also seems unnecessary. I am already using post formats throughout the site, so surely I could just hijack one of the unused post formats (such as ‘status’) and use this to display the full gallery in a different layout to the main single post. I would need to refresh the page when the ‘view more’ link is clicked and update the body class but that shouldn’t be too hard.
So, my question is;
- does anyone know of a custom version of the post_excerpt script that works for images?
- what would be the most efficient way of assembling the database calls (wp_the_query, pre_get_posts) and using is_main_query() to keep on track and avoid the overheads of duplication?
- and how do I refresh the page (to display the gallery) without making an additional database query?
This sounds like an ideal plugin or shortcode which could be used for other mime types (videos, PDFs etc), in fact pretty standard CMS functionality. So in the spirit of open source community, and to save me reinventing the wheel, does any of this sound like a problem you might have already found a solution to?
- The topic ‘Post excerpt functionality for attachments – specifically full-page galleries’ is closed to new replies.