- This topic has 7 replies, 3 voices, and was last updated 9 months, 1 week ago by
Leo.
-
AuthorPosts
-
March 6, 2019 at 11:16 am #830872
Krzysztof
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.
GeneratePress 2.2.2GP Premium 1.7.8March 6, 2019 at 4:26 pm #831096Tom
Lead 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 );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 7, 2019 at 7:01 am #831809Krzysztof
Hey 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 #832258Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJune 24, 2022 at 5:46 am #2263173fragbenny
I 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 #2263226David
StaffCustomer 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.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 24, 2022 at 7:57 am #2263400fragbenny
Ok, 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 #2263458Leo
StaffCustomer SupportThis is something you will need to check with the plugin’s support team.
Thanks!
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.