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