[英]product gallery attachment url in woocommerce
I'm using this snippet to output the product gallery attachments on a custom wordpress template for a woocommerce site.我正在使用此代码段在 woocommerce 网站的自定义 wordpress 模板上输出产品库附件。 I'm using a lightbox for the popup.
我正在为弹出窗口使用灯箱。 But I struggling to get the attachment url, instead it keeps on using the featured image the pop-up.
但我努力获取附件 url,而是继续使用弹出窗口中的特色图像。
<?php
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );
$url = $thumb['0'];
echo '<div>';
foreach( $attachment_ids as $attachment_id )
{
echo '<a href="' . $url . '" rel="shadowbox" >' ."<img src=".$image_link = wp_get_attachment_url( $attachment_id, 'large')." style='width:70px; height:70px;' >". '</a>';
}
echo '</div>';
?>
Any ideas on how to target the correct url path for the product gallery images?关于如何为产品库图片定位正确的 url 路径有什么想法吗? Any help much appreciated!
非常感谢任何帮助!
I have changed 'thumbnail_size'
to 'large'
added global $post;
我已将
'thumbnail_size'
更改为'large'
添加global $post;
and changed .wp_get_attachment_image_src( $attachment_id, 'large').
并更改了
.wp_get_attachment_image_src( $attachment_id, 'large').
. .
The $post
will need to be decalered globaly to access it's contents since this is outside "the loop". $post
需要全局去标以访问它的内容,因为它在“循环”之外。
EDIT 2 I've updated the code below so it should link to the image clicked.编辑 2我已经更新了下面的代码,所以它应该链接到点击的图像。 Removed
$thumb
and $url
as it's not being used.删除了
$thumb
和$url
因为它没有被使用。
<?php
global $product;
global $post;
$attachment_ids = $product->get_gallery_attachment_ids();
echo '<div>';
foreach( $attachment_ids as $attachment_id )
{
echo '<a href="' .wp_get_attachment_image_src( $attachment_id, 'large'). '" rel="shadowbox" >' ."<img src=".wp_get_attachment_image_src( $attachment_id, 'large')." style='width:70px; height:70px;' >". '</a>';
}
echo '</div>';
?>
Hope this will help you希望能帮到你
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
foreach( $attachment_ids as $attachment_id )
{
//Get URL of Gallery Images - default wordpress image sizes
echo $Original_image_url = wp_get_attachment_url( $attachment_id );
echo $full_url = wp_get_attachment_image_src( $attachment_id, 'full' )[0];
echo $medium_url = wp_get_attachment_image_src( $attachment_id, 'medium' )[0];
echo $thumbnail_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail' )[0];
//Get URL of Gallery Images - WooCommerce specific image sizes
echo $shop_thumbnail_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_thumbnail' )[0];
echo $shop_catalog_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_catalog' )[0];
echo $shop_single_image_url = wp_get_attachment_image_src( $attachment_id, 'shop_single' )[0];
//echo Image instead of URL
echo wp_get_attachment_image($attachment_id, 'full');
echo wp_get_attachment_image($attachment_id, 'medium');
echo wp_get_attachment_image($attachment_id, 'thumbnail');
echo wp_get_attachment_image($attachment_id, 'shop_thumbnail');
echo wp_get_attachment_image($attachment_id, 'shop_catalog');
echo wp_get_attachment_image($attachment_id, 'shop_single');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.