Skip to main content

How should I load image from content of post?

Hello,

Please look at my site:

http://bmecommunity.nationbuilder.com/

Go to LATEST BLOG ENTRIES at last, it is a list of blogs. Right now it is showing image of the author, but I want to show image which I put inside the content. So how should I separate this image from content?

Official response from

Hi Varun,

It's possible to select a particular image from a collection of attachments by using a Liquid array element selector.

For example, within your partial template's "for" loop looping over your latest blog entries, you can display just the second image of each post by adding this snippet:

{% if post.attachments.size > 1 %}
   <img src="{{ post.attachments[1].url }}"
{% endif %}

This bit of code first ascertains that there are at least two or more attachments for the post, and, if so, grabs the url of the second image with the array element selector [1] (the first image is located at the 0 index).

Share this post

Showing 2 reactions

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.