CMS Development

CristianSabogal
Member | Elite Partner
Member | Elite Partner

Hubl (Filter-Query) blogs by (Traffic Metrics, Content Metrics, Social Media Metrics)

SOLVE

It's possible create a custom module where I can add controls to filter post by for example:

 

- Most shared post.

- Most viewed Post.

- Etc.

 

Which options are available?

 

Note: I read this source https://developers.hubspot.es/docs/reference/cms/hubl/functions?_gl=1*gom18w*_ga*MTUyMjYwMjA2My4xNzM...

But, I want con confirm the information.

 

Thanks.

0 Upvotes
1 Accepted solution
evaldas
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Hubl (Filter-Query) blogs by (Traffic Metrics, Content Metrics, Social Media Metrics)

SOLVE

Hi @CristianSabogal,

 

It does not look like it would be possible to break down the blog posts by those metrics that could be used in custom modules. 

 

The filtering available for blog posts is:

  • blog_popular_posts (to show popular posts by time frame and/or tag)
  • blog_recent_posts (show most recent posts)
  • blog_recent_author_posts (show most recent posts by author)
  • blog_recent_tag_posts (show most recent posts by tag)

 

The only controls for most popular posts that you could build in the custom module would be allowing editor to select time frame (month, six months, year, all time) and select what tags to filter the posts by.

 


✔️ Did this post help answer your query? Help the community by marking it as a solution.

View solution in original post

3 Replies 3
Markestac
Contributor | Gold Partner
Contributor | Gold Partner

Hubl (Filter-Query) blogs by (Traffic Metrics, Content Metrics, Social Media Metrics)

SOLVE

Hi @CristianSabogal,
* Here's how you can set up custom fields in the HubSpot Module Editor and use them in HubL to filter and display blog posts: You can add Custom Fields in the Module Editor,

example:

1. Blog (Blog Field):
* Add a blog field named "blog" in the module editor.

2. Filter Type (Choice Field):
* Add a dropdown field named "filter_by" in the module editor.
* Example options: Recent Tag Posts, Popular, Recent Posts.

3. Tag Filter (Tag Field):
* Add a tag field named "tag_field".
* Enable repeater option in that field.

4. Number of Posts (Number Field):
* Add a numeric field named "posts_limit".

* Use Fields in HubL        
Below is an example of HubL code that uses these module fields to fetch and display blog posts based on the selected filter:        
Example HubL Code with Inline Module Fields -

{% set filter_by = module.filter_by %}
{% set posts_limit = module.posts_limit %}
{% set blog = module.blog %}
{% set tag_slugs = [] %}
{% for item in module.tag_field %}
{% set tag_slugs = tag_slugs.append(item.slug) %}
{% endfor %}
<div class="filtered-blog-list">
<!-- Fetch the blog posts based on filter type --> {% if filter_by == "tag_posts" %}
<!-- Show the most recent tags posts --> {% set blog_posts = blog_recent_tag_posts(blog, tag_slugs, posts_limit, "AND") %}
{% elif filter_by == "popular" %} <!-- Show the most popular posts --> {% set blog_posts = blog_popular_posts(blog, posts_limit, tag_slugs, "popular_past_month", "AND") %}
{% elif filter_by == "recent" %} <!-- how the most recent posts --> {% set blog_posts = blog_recent_posts(blog, posts_limit) %}
{% endif %} <!-- Render the filtered posts --> {% for post in blog_posts %}<div class="blog-post">
<h2><a href="{{ post.absolute_url }}">
{{ post.name }}</a></h2>
<p>{{ post.publish_date }}</p> <p>{{ post.post_summary }}</p> </div>{% endfor %} </div>

This setup ensures that you can dynamically filter and display blog posts based on the module's custom fields.  

Talk to Our HubSpot Expert

Marketing Automation Agency | RevOps & CRM Consultant

Did my post help answer your query? Help the community by marking it as a solution.

evaldas
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Hubl (Filter-Query) blogs by (Traffic Metrics, Content Metrics, Social Media Metrics)

SOLVE

Hi @CristianSabogal,

 

It does not look like it would be possible to break down the blog posts by those metrics that could be used in custom modules. 

 

The filtering available for blog posts is:

  • blog_popular_posts (to show popular posts by time frame and/or tag)
  • blog_recent_posts (show most recent posts)
  • blog_recent_author_posts (show most recent posts by author)
  • blog_recent_tag_posts (show most recent posts by tag)

 

The only controls for most popular posts that you could build in the custom module would be allowing editor to select time frame (month, six months, year, all time) and select what tags to filter the posts by.

 


✔️ Did this post help answer your query? Help the community by marking it as a solution.

BérangèreL
Community Manager
Community Manager

Hubl (Filter-Query) blogs by (Traffic Metrics, Content Metrics, Social Media Metrics)

SOLVE

Hi @CristianSabogal and Happy New Year! 🎉
Sending you my warmest and best wishes for 2025!

Thanks for asking the Community!

I have found this thread "Set Up A Custom Filter for Blog Posts by Topic" that might be of interest.

Also, I'd love to put you in touch with some of our Top Experts: Hi @evaldas, @IWebteam and @zach_threadint do you have suggestions to help @CristianSabogal, please?

Have a lovely day and thanks so much! ❤️

Best,
Bérangère


Saviez-vous que la Communauté est disponible en Français ?
Rejoignez les discussions francophones en changeant votre langue dans les paramètres !

Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings!