简体   繁体   English

在Shopify中获取博客文章的图像

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

I have to modify a Shopify website with a blog that extracts the content of blog articles using {{ article.content }} . 我必须使用博客修改Shopify网站,该博客使用{{ article.content }}提取博客文章的内容。 This method gets the entire content of an article, but I need to get the images separately. 此方法获取文章的全部内容,但我需要分别获取图像。 I don't mean the 'main' image, but all the images that the content of a blog article contains. 我并不是说“主要”图片,而是博客文章内容包含的所有图片。 How can I do this? 我怎样才能做到这一点? It would be awesome if I could get a JS array containing the paths to the images. 如果我能得到一个包含图像路径的JS数组,那将是非常棒的。

Lets say your article is in a div. 可以说您的文章在div中。 Like 喜欢

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

Now we can put all images under that div into an array. 现在我们可以将该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]);
  }
});

Let me know if that helps. 让我知道是否有帮助。

reference : Get inside all images in array using jquery? 参考: 使用jQuery获取数组中的所有图像?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM