Skip to main content
Inspiring
October 15, 2025
Answered

Add a link to

  • October 15, 2025
  • 2 replies
  • 402 views

I have a newsletter that gets the title of a post, the first 200 characters, then if there are more than 200 characters, text that says [... more].

The title is a link.  I'd like the [... more] text to also be a link, but that is coming from a cfset.

Here is the title text ( removed other styling).  I only need the a href part, just including the rest for context:

<a href="https://www.pathlabtalk.com/forum/index.php?/topic/#tid#-#title_seo#/" style="font-size: 18px; text-decoration: none; color:##417394;">#ThreadTitle#</a>

Here is the [... more] text:

<!--- Set output to 200 characters, full words only --->
<cfif len(TopicPost.post) gt 200>
<cfset trimmedQuote = fullLeft(TopicPost.post, 200)>
<cfset trimmedQuote &= " [... more]">
<cfelse>
<cfset trimmedQuote = TopicPost.post> </cfif>

Is this possible?

Thank you

    Correct answer Charlie Arehart

    Charlie, you are a gentleman, and a patient one at that.

     

    Here is a link to the page I import with my newsletter program.  (I will delete the link later today)

    link removed 

    Depending on when it's viewed, you will see some say [... more] at the end, and some don't.  That is the part I would like to have a link to the post.

     

    I attached the unedited file.  I will delete that later, too.

    file removed


    My wife will concur on my patience. 🙂

    As for your code, here's my proposal: replace the final lines (starting with "<!--- Set output to 200 characters, full words only --->">) with this chunk instead. I've simply moved a couple of your puzzle pieces around, and tweaked another couple, hoping it gets your desired result. There are of course many ways to accomplish a task, and there are still further improvements/refinements one could propose. But let's see if this works for your current need/challenge. 

    Of course, I can't test the code, but you can. (And with a good editor you can easily do an "undo" to remove it all and revert to what you had, if somehow it doesn't work and you don't want to debug it.) And I see also that while I was doing that and about to post this, BKBK offered his own idea. I will send this along and let you consider both.

    <!--- Set output to 200 characters, full words only --->
      <cfset trimmedQuote = TopicPost.post>
      <cfif len(TopicPost.post) gt 200>
      		<cfset trimmedQuote = fullLeft(TopicPost.post, 200)>
    		<cfset trimmedQuote &= " [... more]"> 
      </cfif>
          
      <!--- Strip paragraph format sent from dataabse --->
      <!--- example to strip all tags except B --->
      <p style="font-size:14px; line-height:1.5em; font-family:Verdana, Geneva, sans-serif; color:##50524b;">
      <cfoutput>#tagStripper(trimmedQuote,'strip','b')#</cfoutput>
      <cfif len(TopicPost.post) gt 200>
          <a href="https://www.pathlabtalk.com/forum/index.php?/topic/#tid#-#title_seo#/" style="font-size: 18px; text-decoration: none; color:##417394;"> [... more]</a></div>
      </cfif>
      </p>
      </cfoutput>
        </cfloop>   
        </cfif>

     

    2 replies

    BKBK
    Community Expert
    Community Expert
    October 15, 2025

    I created the following example, based on the information you provided: tid, title_seo and link HTML:

    <cfset tid="myTid1234">
    <cfset title_seo = "My_SEO_9876">
    	
    <cfsavecontent variable="TopicPost.post">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. In non eros fermentum, rhoncus massa vel, fringilla lectus. Pellentesque vel venenatis dui, eget scelerisque nisi. Aliquam commodo lacus ac sem placerat, et vestibulum ligula porta. Curabitur justo justo, viverra mattis nisi faucibus, scelerisque congue leo. Nam dapibus ex ac velit suscipit mattis. Praesent blandit porttitor ultricies. Pellentesque nec orci id eros aliquet suscipit eu vel tortor. Suspendisse potenti. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Suspendisse sed urna nulla. Sed lectus ante, consequat id lacinia ac, condimentum non diam. Maecenas euismod mi ac quam dignissim egestas. Fusce sollicitudin erat eu mauris facilisis, quis facilisis lectus pellentesque.
    
    Mauris a elementum orci, vel lacinia urna. Etiam finibus semper eros, vitae sollicitudin tellus laoreet ultricies. Aenean eu urna non dui congue commodo sit amet porta ex. Donec nec aliquam nibh, ac consequat nunc. Vivamus ultrices, mi in iaculis vehicula, metus risus blandit erat, commodo varius ante massa at metus. Integer at dui quis nisi sagittis porttitor sit amet ut lorem. Sed vel ex cursus odio hendrerit lobortis quis vitae metus.
    
    Praesent sit amet pretium sem. Etiam nec mi vel tellus lacinia vulputate. Fusce elementum, massa scelerisque laoreet accumsan, nibh risus rhoncus mauris, at.
    </cfsavecontent>
    
    <!--- Estimate number of words by counting number of spaces between words --->
    <cfset estimatedNumberOfWords = listLen(TopicPost.post, " ")>
    
    <cfset moreWordsLinkText = '<a href="https://www.pathlabtalk.com/forum/index.php?/topic/#tid#-#title_seo#/" style="font-size: 18px; text-decoration: none; color:##417394;"> [... more]</a>'>
    
    <cfif estimatedNumberOfWords gt 200>	
    	<cfset TopicPost.post &= moreWordsLinkText>
    		
    	<cfoutput>
    		<p>Number of words = #estimatedNumberOfWords#</p>	
    		<p>#topicPost.post#</p>	
    	</cfoutput>
    <cfelse>
    </cfif>
    

    Run it to see whether I understand what you're looking for. 

    The two key lines of code are:

    <cfset moreWordsLinkText = '<a href="https://www.pathlabtalk.com/forum/index.php?/topic/#tid#-#title_seo#/" style="font-size: 18px; text-decoration: none; color:##417394;"> [... more]</a>'>
    

    and

    <cfset TopicPost.post &= moreWordsLinkText>

     

    BKBK
    Community Expert
    Community Expert
    October 15, 2025

    In the example that I provided, I left it up to you to do the truncation to 200 words.

    For completeness, here is the same example, together with a function to truncate text to 200 words.

    <cfset tid="myTid1234">
    <cfset title_seo = "My_SEO_9876">
    	
    <cfsavecontent variable="topicPost.post">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc semper sit amet metus sed fringilla. Proin lectus ipsum, commodo nec euismod ut, bibendum ut mauris. Integer lacinia fermentum lectus, vel ultrices purus luctus vitae. Nam urna eros, suscipit id tempor feugiat, viverra at nisl. Donec velit elit, gravida eu imperdiet at, finibus molestie purus. Donec at nisl malesuada, vulputate ipsum vel, efficitur urna. Ut sagittis vulputate turpis, at pellentesque tellus pretium id. Donec vulputate mi orci, nec aliquet nibh ornare sed. Quisque dapibus pulvinar suscipit. Nunc pretium risus facilisis lorem blandit viverra.
    
    Donec maximus nec sapien ut cursus. Aliquam auctor turpis eget pharetra lobortis. Nullam non hendrerit tellus. Aliquam varius felis vel nisl tincidunt, at tempor sem vehicula. Integer nec erat hendrerit, cursus lectus maximus, sodales est. Quisque varius consectetur ipsum, id varius lorem scelerisque sodales. Praesent in placerat mi, sit amet suscipit turpis. Etiam faucibus maximus tincidunt. Mauris aliquet porttitor nisi, eu facilisis erat gravida nec. In rhoncus nec nulla varius facilisis. Suspendisse eu mollis tellus. Sed at velit convallis neque consectetur blandit.
    
    Donec nec erat rhoncus, molestie felis id, pellentesque ligula. Phasellus in nisl tempor, bibendum ligula non, mattis nibh. Duis porta cursus mi sed feugiat. Praesent pretium velit ac scelerisque sollicitudin. In ut fringilla urna, non scelerisque dolor. Proin at lorem vitae tortor efficitur aliquam. Ut facilisis nunc et tellus convallis, vel placerat metus sollicitudin. Fusce ex justo, posuere quis tortor at, elementum iaculis ipsum. Integer turpis enim, sollicitudin quis dictum in, porttitor at leo. Maecenas tempor.
    </cfsavecontent>
    
    <!--- Estimate number of words by counting number of spaces between words --->
    <cfset estimatedNumberOfWords = listLen(topicPost.post, " ")>
    
    <cfset moreWordsLinkText = '<a href="https://www.pathlabtalk.com/forum/index.php?/topic/#tid#-#title_seo#/" style="font-size: 18px; text-decoration: none; color:##417394;"> [... more]</a>'>
    
    <cfif estimatedNumberOfWords gt 200>	
    	<cfset truncatedText = truncateText(topicPost.post, 200)>
    	<cfset truncatedTextLength = listLen(truncatedText, " ")>
    		
    	<cfset truncatedText &= moreWordsLinkText>
    		
    	<cfoutput>
    		<p>Original Number of words = #estimatedNumberOfWords#</p>	
    		<p>Truncated Number of words = #truncatedTextLength#</p>
    		<p>#truncatedText#</p>	
    	</cfoutput>
    <cfelse>
    </cfif>
    
    <!--- Function to truncate given text to a limited number of words  --->
    <cffunction name="truncateText" returntype="string">
    	<cfargument name="txt">
    	<cfargument name="numberOfWordsLimit">
    		
    	<!--- Convert to array for slicing --->	
    	<cfset var arrayOfWords = listToArray(arguments.txt, " ")> 
    		
    	<cfset var truncatedArrayOfWords = arraySlice(arrayOfWords, 1, arguments.numberOfWordsLimit)>
    	<cfset var truncatedTxt = arrayToList(truncatedArrayOfWords, " ")>
    		
    	<cfreturn truncatedTxt> 
    </cffunction>
    
    ctreevesAuthor
    Inspiring
    October 15, 2025

    Thank you BKBK, I appreciate your help.

    Charlie Arehart
    Community Expert
    Community Expert
    October 15, 2025

    It would seem your href would work as is if you placed it after that cfml code, and changed #ThreadTitle# to #trimmedQuote#.

     

    But somehow I suspect that answer is too obvious and I'm perhaps missing what was your question. If so can you elaborate? 

    /Charlie (troubleshooter, carehart. org)
    ctreevesAuthor
    Inspiring
    October 15, 2025

    Sorry for not being clear, that's what happens when a non-programmer gets their hands on the toys.  🙂

     

    I want this <cfset trimmedQuote &= " [... more]"> to end up as a link.  I tried to add the a href info inside of that, but it gives an error.

     

    Charlie Arehart
    Community Expert
    Community Expert
    October 15, 2025

    Thanks for clarifying your situation. Still, it feels like you didn't quite understand my first answer. Have you at least tried it? I really think it will be your solution.

     

    To be explicit, move the a href to AFTER the closing cfif, and replace the variable referenced there to be this:

     

    <a href="https://www.pathlabtalk.com/forum/index.php?/topic/#tid#-#title_seo#/" style="font-size: 18px; text-decoration: none; color:##417394;">#trimmedQuote#</a>

    /Charlie (troubleshooter, carehart. org)