【问题标题】:Display all images that are assign to a product in woo commerce , wordpress在 woocommerce 、 wordpress 中显示分配给产品的所有图像
【发布时间】:2016-05-22 06:51:54
【问题描述】:

我有一个用 wordpress 设计的正在运行的网站,我正在尝试获取在 woo 商业中定义的产品的所有图像并一个接一个地显示它们我尝试执行以下操作但它没有成功.

<?php while(the_post_thumbnail()) the_post_thumbnail(); ?>

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    如果您想在任何地方获取产品图库图片。你可以试试这个。它将通过 id 获取图像。

     <?php
    
            $product_id = '14';
            $product = new WC_product($product_id);
            $attachment_ids = $product->get_gallery_attachment_ids();
    
            foreach( $attachment_ids as $attachment_id ) 
                {
                  // Display the image URL
                  echo $Original_image_url = wp_get_attachment_url( $attachment_id );
    
                  // Display Image instead of URL
                  echo wp_get_attachment_image($attachment_id, 'full');
    
                }
        ?>
    

    如果您在单个产品页面中显示图像。

    然后

    <?php
        global $product;
    
        $attachment_ids = $product->get_gallery_attachment_ids();
    
        foreach( $attachment_ids as $attachment_id ) 
            {
              // Display the image URL
              echo $Original_image_url = wp_get_attachment_url( $attachment_id );
    
              // Display Image instead of URL
              echo wp_get_attachment_image($attachment_id, 'full');
    
            }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      • 2015-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      相关资源
      最近更新 更多