Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add a link to

Explorer ,
Oct 15, 2025 Oct 15, 2025

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

350
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 15, 2025 Oct 15, 2025

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/cha

...
Translate
Community Expert ,
Oct 15, 2025 Oct 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)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 15, 2025 Oct 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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2025 Oct 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)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 15, 2025 Oct 15, 2025

Here's the whole content, I tried to make it simpler (for me) by only posting a part of it, but it seems I likely made it worse.

<cfif isdefined('URL.ID')>

<cfswitch expression="#URL.ID#">
<cfcase value=1>
AND
forum_id IN ('7','64','20','21','13','9','6','25','24','8','12','26','10','14','33','28','32')
</cfcase>
<cfcase value=2>
AND
forum_id IN ('75','56','54')
</cfcase>
<cfcase value=3>
AND
forum_id IN ('77','55')
</cfcase>
<cfcase value=4>
AND
forum_id IN ('76','50')
</cfcase>
<cfcase value=5>
AND
forum_id IN ('80','84','85')
</cfcase>
</cfswitch>
<cfelse>

</cfif>

ORDER BY
last_post DESC

</cfquery>


<cfloop query="NewPosts">
<cfoutput>
<div style="font-family:Verdana, Geneva, sans-serif; border-bottom:dashed 1px ##88bfce; padding:5px 0px 5px 0px; margin:0px; color:##006666; font-size:18px; font-weight:normal;"><a href="https://www.pathlabtalk.com/forum/index.php?/topic/#tid#-#title_seo#/" style="font-size: 18px; text-decoration: none; color:##417394;">#ThreadTitle# (#last_poster_name#)</a></div>

<cfquery name="TopicPost" datasource="#DSN4#">
Select
post
FROM
IPS_forums_posts
Where
new_topic = 1 AND
topic_id = #tid#
</cfquery>
<!--- 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>

<!--- Strip paragraph format sent from dataabse --->
<cfsavecontent variable="myString">
#trimmedQuote#
</cfsavecontent>
<!--- 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(myString,'strip','b')#</cfoutput></p>
</cfoutput>
</cfloop>
</cfif>

 

---

Using 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>

gives this

Invalid CFML construct found on line 346 at column 24.

ColdFusion was looking at the following text:

&lt;

The CFML compiler was processing:

    &lt; marks the beginning of a ColdFusion tag.Did you mean LT or LTE?
  • A cfset tag beginning on line 346, column 18.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2025 Oct 15, 2025

Are you saying that making only the change in the var name used in the a href introduced that error? I'd be very surprised.

 

Anyway. What, if any, of those 3 cfset's is the line 346 mentioned in the error as doing a cfset?

 

And do you have (anywhere in the hundreds of lines not shown) a "&lt", as is implied in the error message?

 

BTW, if you get tempted to share the hundreds of lines in a reply, please don't. There's a feature to attach a file here. And if that fails for you, consider putting it somewhere and linking to it (assuming it's not sensitive code, of course). 


/Charlie (troubleshooter, carehart. org)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 15, 2025 Oct 15, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2025 Oct 15, 2025

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>

 


/Charlie (troubleshooter, carehart. org)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 15, 2025 Oct 15, 2025

Thank you, I did make one small change.  I needed to remove the [... more] in the cfset statement.

I really appreciate your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2025 Oct 15, 2025
LATEST

Ah, yes: I copied when I should have cut. 🙂

 

Glad things are working for you. 


/Charlie (troubleshooter, carehart. org)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2025 Oct 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>

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2025 Oct 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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 15, 2025 Oct 15, 2025

Thank you BKBK, I appreciate your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources