Jump to content

How to make summary block image for blog a clickable link? Wells template.

Go to solution Solved by paul2009,

Recommended Posts

please have a look at the attached screenshot, how could i make the image clickable and linked to the corresponding blog entry? a general solution working for all the site would be preferable. thank you so much for helping out. markus

Screen Shot 2023-08-28 at 15.33.56.png

Markus Gröteke

Architectural, interior, art and exhibition photography.
Web: architectureshooting.com | Instagram: architectureshooting

Link to comment
  • Solution
On 8/28/2023 at 2:42 PM, architectureshooting said:

how could i make the image clickable and linked to the corresponding blog entry?

Your screenshot shows a Blog List Page and so the main image of a post isn't linked.

If you're on a Business Plan or higher, some JavaScript can be written to pull the URL from each post title and then wrap a duplicate link around the main-image of the post. A simplified version (to add to the Footer Code Injection) might look something like this:

<script>
const articles = document.querySelectorAll('article');
articles.forEach(article => {
  const h1Link = article.querySelector('header h1.entry-title a');
  const mainImageDiv = article.querySelector('.main-image');
  if (h1Link && mainImageDiv) {
    const url = h1Link.href;
    const link = document.createElement('a');
    link.href = url;
    mainImageDiv.parentNode.insertBefore(link, mainImageDiv);
    link.appendChild(mainImageDiv);
  }
});
</script>

This script will find the blog posts (articles) on the page and then iterate through each article to grab the URL being used by the h1 link in each article's header. It will then wrap the main-image div within each article with a duplicate link using the same URL.  Like all code on the forum, this is just an example. It hasn't been extensively tested or designed to apply to lazy-loaded posts that might load later.

In this recording you'll see that each image is now linked, as shown by the link description (bottom-right) that appears when the pointer hovers over one of the images:

image.thumb.gif.c56195cec0e0ca9261a6d16e570377d6.gif

 

Did this help? Please give feedback by clicking an icon below  ⬇️

About me: I've been a SQSP User for 18 yrs. I was invited to join the Circle when it launched in 2016. I have been a Circle Leader since 2017. I don't work for Squarespace. I value honesty, transparency, diversity and good design ♥.
Work: I founded and run SF.DIGITAL, building Squarespace Extensions to supercharge your commerce website. 
Content: Views and opinions are my own. Links in my posts may refer to SF.DIGITAL products or may be affiliate links.
Forum advice is free. You can thank me by clicking one of the feedback emojis below. Coffee is optional.

Link to comment
  • 2 weeks later...
26 minutes ago, architectureshooting said:

thank you so much, this was really helpful

You're welcome.

26 minutes ago, architectureshooting said:

it is working well with almost all of my blog post entries

The solution won't modify blog posts that have a Promoted Block. Promoted Blocks are a special feature on older templates like Wells, where they treat the first block in a blog post differently. In this case forcing the Promoted Block to appear above the title.

If you don't like how promoted blocks look on your site, you can disable them in Website > Design > Template Settings:

image.png.27bdb667b591da60d103344c3f188c7e.png

Alternatively, if you want to decide on a post-by-post basis, you can reformat an individual post to avoid the first block being promoted. For example, if the first block in the post is an Image Block, you could add a single line Text Block just above it.

I hope this helps to explain 🙂

Did this help? Please give feedback by clicking an icon below  ⬇️

Edited by paul2009

About me: I've been a SQSP User for 18 yrs. I was invited to join the Circle when it launched in 2016. I have been a Circle Leader since 2017. I don't work for Squarespace. I value honesty, transparency, diversity and good design ♥.
Work: I founded and run SF.DIGITAL, building Squarespace Extensions to supercharge your commerce website. 
Content: Views and opinions are my own. Links in my posts may refer to SF.DIGITAL products or may be affiliate links.
Forum advice is free. You can thank me by clicking one of the feedback emojis below. Coffee is optional.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.