Hi,
I am new to ghost. I was checking different scenarios and I was thinking if thers any way to display a default image in post card image when no image is added.?
Thanks in advance
Hi,
I am new to ghost. I was checking different scenarios and I was thinking if thers any way to display a default image in post card image when no image is added.?
Thanks in advance
Sure, you’d just have to edit the appropriate portion of your theme and include an {{#if}}
{{else}}
statement, something like this:
{{#if feature_image}}
<img src="{{img_url feature_image}}">
{{else}}
<img src="YOUR_IMAGE_URL">
{{/if}}
That way, if there’s been no feature image uploaded then the post will default to whatever you’ve set up as YOUR_IMAGE_URL
.
hey thanks for the info.
but also i was confused about different sizes,
the default code is like this,
<img class="post-card-image" srcset="{{img_url feature_image size="s"}} 300w,
{{img_url feature_image size="m"}} 600w,
{{img_url feature_image size="l"}} 1000w,
{{img_url feature_image size="xl"}} 2000w" sizes="(max-width: 1000px) 400px, 700px"
src="{{img_url feature_image size="m"}}" alt="{{title}}" />
so if i add an image as the default image, how will i give these different width options?
You could do the same thing
<img class="post-card-image" srcset="{{img_url YOUR_IMAGE size="s"}} 300w,
{{img_url YOUR_IMAGE size="m"}} 600w,
{{img_url YOUR_IMAGE size="l"}} 1000w,
{{img_url YOUR_IMAGE size="xl"}} 2000w" sizes="(max-width: 1000px) 400px, 700px"
src="{{img_url YOUR_IMAGE size="m"}}" alt="{{title}}" />
You might need to use the asset helper to reference your image. It should work like this, though I’m not 100% sure {{img_url (asset "YOUR_IMAGE") size="l"}}