Jump to content

simon_clarke

Member
  • Posts

    1
  • Joined

  • Last visited

Posts posted by simon_clarke

  1. On 8/14/2020 at 3:23 PM, RyanDejaegher said:

    @StoriedCorey and @emilykrause  Add this code to Settings -> Advanced -> Code Injection -> Footer

    You can adjust the var characterCount to a different number to adjust how much it cuts off. You can also adjust the "trail".

    This code will also only cut full words, that way it doesn't cut it at weird points. i.e. "Learn more about Squaresp...."

     

    <script>
    (function(){
    	window.addEventListener('load', function() {
    	var characterCount = 140
    	var blogParagraph = document.querySelectorAll('.BlogList-item-excerpt p')
    	var trail = "..."
        
    	// Shorten a string to less than maxLen characters without truncating words.
    function shorten(str, maxLen, separator = ' ') {
      if (str.length <= maxLen) return str;
      return str.substr(0, str.lastIndexOf(separator, maxLen));
    }
    
    blogParagraph.forEach(item => {
        item.textContent = shorten(item.textContent, characterCount) + trail;
    })
    
    })
    
    })()
    </script>

     

    I tried this with my site but it didn't work. It's using v7.1, but for some reason Squarespace doesn't want me to know which template I chose, and I can't remember. I can't find the disable Ajax control in site styles either. The url is wilsonwillis.squarespace.com – but the blog pages are disabled for now as they are not ready for public view. Should this script still work for me? Sorry I may not have given enough information for this query...

    UPDATE: I realised that I wanted a script to apply to a summary block, not a blog post page. So the scripts here didn't work. I found a script here that did...

    https://nestingzone.com/design-blog/how-limit-blog-post-excerpt-word-count

     

     

×
×
  • 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.