Hi, srcset is standard with WordPress now.
single_photoswipe might be embedded in your theme. The plugin doesn’t make any permanent changes to your site.
Hi is there anything we need to do to make srcset work with photoseipe?
We load the images with acf gallery and on mobile it’s loading the full size images, the same as desktop.
Are you using our plugin with acf gallery?
Yes we are, as it’s easier for the client in the admin than WordPress gallery
Hmm, can you explain how you got that working? Did you edit the plugin?
Please note we didn’t make the gallery > http://photoswipe.com/
yep, here you go
<?php
$image_ids = get_field('gallery_images', false, false);
$shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]';
echo do_shortcode( $shortcode );
?>
This loads in the images from acf
We also then set the thumbnail sizes in the photoswipe settings to 0 0 and added the following css
.psgal figure {
width: 25%!important;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
padding: 2px!important;
}
.psgal figure img {
width: 100%!important;
height: auto!important;
padding: 0px!important;
}
.psgal figure a {
width: 100%!important;
height: auto!important;
}
This makes the images fully responsive, so we can set the width to 50% mobile and 33.33% ipad etc and change the columns loaded by masonry.
Not sure if this is needed in all cases, I but I found I had to also add the image sizes to functions.php probably as I had set thumbnails to 0 0 to take control of sizes.
add_image_size( 'photoswipe_thumbnails', 400, 9999, false );
add_image_size( 'photoswipe_full', 1800, 9999, false );
Of course, someone could also have cropped images so they have a consistent grid of images but in this case we are using Masonry so it makes sense to have auto height.
-
This reply was modified 8 years, 11 months ago by
sguk. Reason: formatted code and added additional css tag
-
This reply was modified 8 years, 11 months ago by
sguk. Reason: Added image sizes code and comment
-
This reply was modified 8 years, 11 months ago by
sguk.
ps noted that your plugin “uses” photoswipe and yes you’re right of course, to make photoswipe use conditional images/ srcset would require some modification to the photoswipe js or php files.
Thanks for posting the code. We use ACF for all our sites in-house but I was just curious. This might be useful for others also.
sguk, you said:
Yes we are, as itβs easier for the client in the admin than WordPress gallery
Would you please explain why or how it’s easier for the client in the admin?
Wordpress Gallery has improved since I last looked at it, I only realised recently you can now reorder by editing the gallery etc.
If the whole admin uses ACF I find it’s better as ACF isn’t a wysiwyg area, so you don’t need to explain to the client to click “add media” then create gallery etc.
In ACF it’s already a gallery field and there’s also no possibility they will try to put text there or a static image.
In a custom built theme with specific page areas coded in, ACF gallery ensures instantly the client knows how to use it, can reorder, etc and see cearly what that area is.
Obviously whether it’s easier or not is open to opinion, but in our case it is. This doesn’t however suggest there is anything wrong with WordPress Gallery itself.
The other thing is WordPress Gallery lets you set the columns, I’m not sure how this would interrupt coding when using ACF gallery to do other things like add images for a fading slider etc.
So again, just depends on usage.
Hope this helps π
Hello, Thanks for your explanation. If ACF gallery isn’t in the wysiwyg area, then the gallery has to appear in the preset area – correct? On my site, I drop in multiple galleries in different parts of the text, depending on the particular post. That kind of flexibility (on the fly placement of galleries) is NOT possible with ACF Gallery, correct?
Also is ACF Gallery attached to the post – or can you reuse the same gallery in other posts?
This is where your usage can vary when you are not staying within a design layout.
However, ACF has a flexible fields option where you can have pre-coded multiple choice content areas, such as gallery, text with header, 2 column text you, image area etc + you can drag and drop the order of these.
ACF gallery is attached to a post, but any post content can be pulled into another post or page. You can also use the global option or you can probably code in shortcodes too.
ps qnother one which can be dropped in as and when is nextgen gallery. It’s separate from the normal media library and you can create multiple galleries in a separate section of wordpress. Each gallery has a shortcode ID and allows you to place it anywhere in your site.
You can then update the gallery from within the nextgen page.