CMS Development

cronhs
Member

Custom RSS feed by tag

SOLVE

Hi there. I am trying to work out how to create a custom RSS feed but instead of having it by most recent, be able to choose to show posts by a chosen tag, like the default RSS module allows you to do. 

 

I know how to add in the selector to the module but not how to get the filter to actually work in the HTML + HUBL.

 

I did find this starter code for 3 posts in a row but this is by most recent

 

{% set rec_posts = blog_recent_posts('default', 3) %}
<div class="row-fluid-wrapper">
<div class="row-fluid">

{% for rec_post in rec_posts %}

<div class="span4">
<a href="{{rec_post.absolute_url}}">
<img src="{{ rec_post.post_list_summary_featured_image }}" alt="{{ rec_post.featured_image_alt_text }}">
<h3>{{ rec_post.name }}</h3>
</a>
</div>

{% endfor %}

</div>
</div>

 

Any help?

0 Upvotes
1 Accepted solution
Jsum
Solution
Key Advisor

Custom RSS feed by tag

SOLVE

Hi @cronhs ,

 

You can do this in the custom module editor:

 

First, you will want to grab the code for the blog_recent_tag_posts function from the HubL docs. That looks like this:

{% set tag_posts = blog_recent_tag_posts('default', 'marketing-tips', 5) %}
{% for tag_post in tag_posts %}
    <div class="post-title">{{ tag_post.name }}</div>
{% endfor %}

You can provide an option, for the topic to filter by, in the page editor by using a custom module text field. Create a plain text field in the module, and apply the token (not the snippet) where 'marketing-tips' is:

{% set tag_posts = blog_recent_tag_posts('default', {{ text_field_value }}, 5) %}

how this works is that you would enter a value to the text field in the editor. That value will print, as a string, where the token exists.

There is a hangup here. If the value entered doesn't register as a topic it will break the feed. It would be great if there was a "blog topics" field that supplied a drop down choice of blog topics, but that isn't the case. The text field is the best option I have found, but user experience is iffy because the value entered has to exist, and also has to be correctly formated as lower case and dashes instead of spaces. While I do not have a solution for ensuring that the text entered is an available topic in your portal, I do have a solution for the formatting:

{% set tag_posts = blog_recent_tag_posts('default', {{ text_field_value|lower|replace(' ', '-') }}, 5) %}

using the HubL lower and replace filters You can convert text entered into the field into the proper format.

 

Let me know if that helps.

 

Need help? Hire Us Here

View solution in original post

5 Replies 5
Jsum
Solution
Key Advisor

Custom RSS feed by tag

SOLVE

Hi @cronhs ,

 

You can do this in the custom module editor:

 

First, you will want to grab the code for the blog_recent_tag_posts function from the HubL docs. That looks like this:

{% set tag_posts = blog_recent_tag_posts('default', 'marketing-tips', 5) %}
{% for tag_post in tag_posts %}
    <div class="post-title">{{ tag_post.name }}</div>
{% endfor %}

You can provide an option, for the topic to filter by, in the page editor by using a custom module text field. Create a plain text field in the module, and apply the token (not the snippet) where 'marketing-tips' is:

{% set tag_posts = blog_recent_tag_posts('default', {{ text_field_value }}, 5) %}

how this works is that you would enter a value to the text field in the editor. That value will print, as a string, where the token exists.

There is a hangup here. If the value entered doesn't register as a topic it will break the feed. It would be great if there was a "blog topics" field that supplied a drop down choice of blog topics, but that isn't the case. The text field is the best option I have found, but user experience is iffy because the value entered has to exist, and also has to be correctly formated as lower case and dashes instead of spaces. While I do not have a solution for ensuring that the text entered is an available topic in your portal, I do have a solution for the formatting:

{% set tag_posts = blog_recent_tag_posts('default', {{ text_field_value|lower|replace(' ', '-') }}, 5) %}

using the HubL lower and replace filters You can convert text entered into the field into the proper format.

 

Let me know if that helps.

 

Need help? Hire Us Here

vanessabt
Participant | Diamond Partner
Participant | Diamond Partner

Custom RSS feed by tag

SOLVE

Is there a way to pull this into a non-hubspot site and filter by tag?

0 Upvotes
Jsum
Key Advisor

Custom RSS feed by tag

SOLVE

@vanessabt you can use the rss feed for your blog. I think topics come through the feed.

cronhs
Member

Custom RSS feed by tag

SOLVE

Thanks so much! 

0 Upvotes
jennysowyrda
Community Manager
Community Manager

Custom RSS feed by tag

SOLVE

Hi @cronhs,

 

Are you still looking for help with this? 

 

Can you please share links, screenshots and examples that you have seen with the type of set up you are looking for? 

I also wanted to share this thread, which discusses a similar topic.

 

Thank you,

Jenny

0 Upvotes