<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Add blog tag URL's and limit post summary characters in JS callback for recent blog posts in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Add-blog-tag-URL-s-and-limit-post-summary-characters-in-JS/m-p/787426#M33965</link>
    <description>&lt;P&gt;Hi &lt;STRONG&gt;jwill377&lt;/STRONG&gt;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nice to meet you, T&lt;STRONG&gt;omas Gaitan, Technical Implementation Specialist at HAL Company, HubSpot Diamond Partner.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To add the blog tag URLs, you can modify the formatting variable inside the loop to include an anchor tag for each tag. Here is an example of how you can modify the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;var formatted = "&amp;lt;div&amp;gt;";&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;for (var i = 0; i &amp;lt; blogposts.length; i++) {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;var blogpost = blogposts[i];&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += '&amp;lt;div class="related-blog-item"&amp;gt;';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;if (blogpost.featuredImage) {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += `&amp;lt;img src="${blogpost.featuredImage}" alt="${blogpost.featuredImageAltText}"&amp;gt;`;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += '&amp;lt;div class="related-blog-tags"&amp;gt;';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;if (blogpost.tagList.length &amp;gt; 0) {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += `${blogpost.tagList.map(tag =&amp;gt; `&amp;lt;a href="${tag.url}" class="blog-tag"&amp;gt;${tag.label}&amp;lt;/a&amp;gt;`).join(", ")}`;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += '&amp;lt;/div&amp;gt;';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += `&amp;lt;a class="related-blog-title" href="${blogpost.url}"&amp;gt;&amp;lt;span&amp;gt;${blogpost.name}&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;`;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += `&amp;lt;p class="related-blog-post-summary"&amp;gt;${blogpost.postSummary.substring(0, 100)}...&amp;lt;/p&amp;gt;`;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += '&amp;lt;/div&amp;gt;';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += "&amp;lt;/div&amp;gt;";&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return formatted;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this modified code, we are using &lt;STRONG&gt;map()&lt;/STRONG&gt; to create an anchor tag for each tag in the tagList, and using the url property of each tag to create the href attribute of the anchor tag. We are also adding a &lt;STRONG&gt;class="blog-tag"&lt;/STRONG&gt; to the anchor tag so you can style it as needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To truncate the characters in the post summary, we will use the &lt;STRONG&gt;substring()&lt;/STRONG&gt; method to get the first 100 characters of the postSummary property and add an ellipsis at the end. You can adjust the number of characters as needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I remain attentive to any questions or queries you may have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
    <pubDate>Thu, 27 Apr 2023 20:17:57 GMT</pubDate>
    <dc:creator>tomasgaitan1</dc:creator>
    <dc:date>2023-04-27T20:17:57Z</dc:date>
    <item>
      <title>Add blog tag URL's and limit post summary characters in JS callback for recent blog posts</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Add-blog-tag-URL-s-and-limit-post-summary-characters-in-JS/m-p/787368#M33963</link>
      <description>&lt;P&gt;Hello! I am trying to get the url's for the blog tags added into the JS callback for recent blog posts. I would also like to truncate the summary post characters and am having issues getting both of these to work. I am using this code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;div class="blog-recent-posts__list"&amp;gt;&lt;BR /&gt;{% related_blog_posts limit=3, callback="blog_post_formatter" %}&lt;/P&gt;&lt;P&gt;&amp;lt;script&amp;gt;&lt;BR /&gt;var blog_post_formatter = function(blogposts) {&lt;/P&gt;&lt;P&gt;var formatted = "&amp;lt;div&amp;gt;";&lt;BR /&gt;for (var i = 0; i &amp;lt; blogposts.length; i++) {&lt;BR /&gt;var blogpost = blogposts[i];&lt;BR /&gt;formatted += '&amp;lt;div class="related-blog-item"&amp;gt;';&lt;BR /&gt;if (blogpost.featuredImage) {&lt;BR /&gt;formatted += `&amp;lt;img src="${blogpost.featuredImage}" alt="${blogpost.featuredImageAltText}"&amp;gt;`;&lt;BR /&gt;}&lt;BR /&gt;formatted += '&amp;lt;div class="related-blog-tags"&amp;gt;';&lt;BR /&gt;if (blogpost.tagList.length &amp;gt; 0) {&lt;BR /&gt;formatted += `${blogpost.tagList.map(tag =&amp;gt; tag.label).join(", ")}`;&lt;BR /&gt;}&lt;BR /&gt;formatted += '&amp;lt;/div&amp;gt;';&lt;BR /&gt;formatted += `&amp;lt;a class="related-blog-title" href="${blogpost.url}"&amp;gt;&amp;lt;span&amp;gt;${blogpost.name}&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;`;&lt;BR /&gt;formatted += `&amp;lt;p class="related-blog-post-summary"&amp;gt;${blogpost.postSummary}&amp;lt;/p&amp;gt;`;&lt;BR /&gt;formatted += '&amp;lt;/div&amp;gt;';&lt;BR /&gt;}&lt;BR /&gt;return formatted;&lt;BR /&gt;}&lt;BR /&gt;&amp;lt;/script&amp;gt;&lt;BR /&gt;&amp;lt;/div&amp;gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 17:51:54 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Add-blog-tag-URL-s-and-limit-post-summary-characters-in-JS/m-p/787368#M33963</guid>
      <dc:creator>jwill377</dc:creator>
      <dc:date>2023-04-27T17:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Add blog tag URL's and limit post summary characters in JS callback for recent blog posts</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Add-blog-tag-URL-s-and-limit-post-summary-characters-in-JS/m-p/787426#M33965</link>
      <description>&lt;P&gt;Hi &lt;STRONG&gt;jwill377&lt;/STRONG&gt;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nice to meet you, T&lt;STRONG&gt;omas Gaitan, Technical Implementation Specialist at HAL Company, HubSpot Diamond Partner.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To add the blog tag URLs, you can modify the formatting variable inside the loop to include an anchor tag for each tag. Here is an example of how you can modify the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;var formatted = "&amp;lt;div&amp;gt;";&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;for (var i = 0; i &amp;lt; blogposts.length; i++) {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;var blogpost = blogposts[i];&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += '&amp;lt;div class="related-blog-item"&amp;gt;';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;if (blogpost.featuredImage) {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += `&amp;lt;img src="${blogpost.featuredImage}" alt="${blogpost.featuredImageAltText}"&amp;gt;`;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += '&amp;lt;div class="related-blog-tags"&amp;gt;';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;if (blogpost.tagList.length &amp;gt; 0) {&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += `${blogpost.tagList.map(tag =&amp;gt; `&amp;lt;a href="${tag.url}" class="blog-tag"&amp;gt;${tag.label}&amp;lt;/a&amp;gt;`).join(", ")}`;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += '&amp;lt;/div&amp;gt;';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += `&amp;lt;a class="related-blog-title" href="${blogpost.url}"&amp;gt;&amp;lt;span&amp;gt;${blogpost.name}&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;`;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += `&amp;lt;p class="related-blog-post-summary"&amp;gt;${blogpost.postSummary.substring(0, 100)}...&amp;lt;/p&amp;gt;`;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += '&amp;lt;/div&amp;gt;';&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;formatted += "&amp;lt;/div&amp;gt;";&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return formatted;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this modified code, we are using &lt;STRONG&gt;map()&lt;/STRONG&gt; to create an anchor tag for each tag in the tagList, and using the url property of each tag to create the href attribute of the anchor tag. We are also adding a &lt;STRONG&gt;class="blog-tag"&lt;/STRONG&gt; to the anchor tag so you can style it as needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To truncate the characters in the post summary, we will use the &lt;STRONG&gt;substring()&lt;/STRONG&gt; method to get the first 100 characters of the postSummary property and add an ellipsis at the end. You can adjust the number of characters as needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I remain attentive to any questions or queries you may have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 20:17:57 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Add-blog-tag-URL-s-and-limit-post-summary-characters-in-JS/m-p/787426#M33965</guid>
      <dc:creator>tomasgaitan1</dc:creator>
      <dc:date>2023-04-27T20:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Add blog tag URL's and limit post summary characters in JS callback for recent blog posts</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Add-blog-tag-URL-s-and-limit-post-summary-characters-in-JS/m-p/788446#M33995</link>
      <description>&lt;P&gt;Thank you so much!!&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 18:16:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Add-blog-tag-URL-s-and-limit-post-summary-characters-in-JS/m-p/788446#M33995</guid>
      <dc:creator>jwill377</dc:creator>
      <dc:date>2023-05-01T18:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Add blog tag URL's and limit post summary characters in JS callback for recent blog posts</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Add-blog-tag-URL-s-and-limit-post-summary-characters-in-JS/m-p/923022#M37906</link>
      <description>&lt;P&gt;Hello!&amp;nbsp;&lt;BR /&gt;Thank you for your response, it was very helpful. The code is returning all the correct tags associated with the post, however, it&amp;nbsp;seems that the URL for the tags (links to the tag detail pages) is returning "undefined".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;PRE&gt;if (blogpost.tagList.length &amp;gt; 0) {&lt;BR /&gt;formatted += '&amp;lt;div class="blog-listing__post-tags"&amp;gt;';&lt;BR /&gt;formatted += blogpost.tagList.map(tag =&amp;gt; `&amp;lt;a href="${tag.url}" class="blog-tag"&amp;gt;${tag.label}&amp;lt;/a&amp;gt;`).join(" ");&lt;BR /&gt;formatted += '&amp;lt;/div&amp;gt;';&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 03:41:23 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Add-blog-tag-URL-s-and-limit-post-summary-characters-in-JS/m-p/923022#M37906</guid>
      <dc:creator>GFW-MillerM</dc:creator>
      <dc:date>2024-02-15T03:41:23Z</dc:date>
    </item>
  </channel>
</rss>

