簡體   English   中英

在Shopify中獲取博客文章的圖像

[英]Get the images of a blog article in Shopify

我必須使用博客修改Shopify網站,該博客使用{{ article.content }}提取博客文章的內容。 此方法獲取文章的全部內容,但我需要分別獲取圖像。 我並不是說“主要”圖片,而是博客文章內容包含的所有圖片。 我怎樣才能做到這一點? 如果我能得到一個包含圖像路徑的JS數組,那將是非常棒的。

可以說您的文章在div中。 喜歡

<div class="article-content">{{ article.content }}</div>

現在我們可以將該div下的所有圖像放入一個數組中。

$(document).ready(function(){

  // To save all images in an array named img_array
  var img_array = $('.article-content img').map(function() {
    return $(this).attr("src");
  });

  // You can run a for loop to display the images in the array.
  for (var i=0; i<img_array.length; i++) {
    alert(img_array[i]);
  }
});

讓我知道是否有幫助。

參考: 使用jQuery獲取數組中的所有圖像?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM