Jump to content

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

Go to solution Solved by paul2009,

Recommended Posts

  • 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  ⬇️

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

Would you like your customers to be able to mark their favourite products in your Squarespace store?

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

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

Would you like your customers to be able to mark their favourite products in your Squarespace store?

Link to comment
  • 1 year later...

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.