- This topic has 7 replies, 3 voices, and was last updated 1 year, 10 months ago by Leo.
-
AuthorPosts
-
March 6, 2019 at 11:16 am #830872Krzysztof
Hello I am working currently on a project which requires me on single product page to display big image which is always first in gallery added to said product. Found the code on web which seems to get things going, but I can’t figure out why it requests images which are not first from woo gallery attached to the product.
Here is the snippet with shortcode:function gal_first_image_shortcode( $atts, $content = null ) { extract( shortcode_atts( array( 'size' => 'shop_single' ), $atts ) ); $images = get_children(array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => 1, 'post_mime_type' => 'image', 'orderby' => 'menu_order', ) ); if($images) { $gallery = ''; foreach( $images as $image ) { $gallery .= wp_get_attachment_image($image->ID, $image_size); } $gallery .= ''; return $gallery; } } add_shortcode('woo_first_gal', 'gal_first_image_shortcode');
It does return image, but not first when looking at the attached gallery table.
March 6, 2019 at 4:26 pm #831096TomLead DeveloperLead DeveloperHi there,
I’m not 100% sure, but you should be able to do something like this:
$product = wc_get_product( get_the_ID() ); $images = $product->get_gallery_image_ids(); $first = $images[0]; $url = wp_get_attachment_url( $first );
March 7, 2019 at 7:01 am #831809KrzysztofHey Tom, thanks for reply. So I should just dump my entire code and replace it with Yours?
Actually, it works in this way:function gal_first_image_shortcode( $atts, $content = null ) { $product = wc_get_product( get_the_ID() ); $images = $product->get_gallery_image_ids(); $first = $images[0]; $url = wp_get_attachment_image( $first, $size='shop_single'); return $url; } add_shortcode('woo_first_gal', 'gal_first_image_shortcode');
Thanks a lot!
March 7, 2019 at 3:42 pm #832258TomLead DeveloperLead DeveloperYou’re welcome 🙂
June 24, 2022 at 5:46 am #2263173BennyI used the code provided above and it works just fine but is there way to make it a gallery with dots to scroll the images?
June 24, 2022 at 7:05 am #2263226DavidStaffCustomer SupportHi there,
you would need to incorporate slider script of some kind to do that, which is out of our scope.
Might be worth googling to see if theres a plugin that already does this.June 24, 2022 at 7:57 am #2263400BennyOk, so i bought this one –> https://woocommerce.com/de-de/products/product-gallery-slider-for-woocommerce/
But there is one little thing, i need help with. I would like it mobile to be fullwidth. Maybe you see it here –> http://avantal.axmxvonbiw-v1p3z0dkj6ye.p.runcloud.link/milbentest/
June 24, 2022 at 9:07 am #2263458LeoStaffCustomer SupportThis is something you will need to check with the plugin’s support team.
Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.