Creating a blog category button

Hi,

I am trying to create a button on the blog index page that will take the user to a specific catagory (tag) page.

Here is the code I have right now:

<div class=“article_list_cta”>
<a class=“black-white-button” style=“color: white” href=“{{ blog_tag_url(“Media_Coverage”, module.blog_post_tag) }}”>View All Coverage</a>
</div>

I think it is a simple fix but I have been beating my head aginst the wall to figure it out so any help would be greatly appreciated.

Thanks

Scott

After thinking about this I think it is becasue it is not in the default blog. It is in a second blog with a different name. How do I change the code to include the blog indicator?

Hi @SlimSr2003

By ensuring that you’ve already created the category (tag) named “Media_Coverage” in your HubSpot blog settings

Try this code and see if you could able to fix this:

<div class=“article_list_cta”>

<a class=“black-white-button” style=“color: white” href=“{{ blog_category_url(“Media_Coverage”) }}”>View All Coverage</a>

</div>

The changes what i recommend is all about the below one - for your reference:

  • Use the {{ blog_category_url(“Media_Coverage”) }} template tag instead. This tag specifically builds a URL for a blog category (tag) based on its name.
  • Remove module.blog_post_tag from the code. This part seems unnecessary for generating the category URL.

Hope this helps - Happy to help further!!
Thank you very much and have a great one!
Warm regards

Hi Humashankar,

Thanks for the reply. The consul is giving me an error when I put that code into that line.

Any other ideas?

With the previous code here is the error it was prodcuing;

SlimSr2003_1-1715602502190.png

You can view the page here: Newsroom if this helps.

Any additioanl help you can provide would be greatly apprciated.

Thanks

Scott

Hi @SlimSr2003

It appears to be two separate issues,

1) The error message “Invalid Blog ID ‘Press release’ passed to blog_tag_URL” suggests that you may be using an incorrect parameter with the {{ blog_tag_url }} template tag, which we previously advised against using.

Resolution - Simply remove {{ blog_tag_url }} entirely from your code. As we discussed earlier, the correct tag for generating category URLs is {{ blog_category_url(“Media_Coverage”) }}

2) error message “blog_tag_url(): tag not found by slug: null” indicates that the {{ blog_tag_url }} code (if you still have it) is attempting to find a non-existent tag.

Resolution - Verify that the category (tag) named “Media_Coverage” is correctly set up in your HubSpot blog settings.

- If you’re using a different category name, simply update the code with the correct name: {{ blog_category_url(“YourCategoryName”) }}

Hope this helps - Happy to help further!!
Thank you very much and have a great one!
Warm regards

Hi Humashankar,

I have replaced both of the code sections that are trying to generate the Blog URL with your code.

Here is the first section:

<div class=“release_list_cta”>
<a class=“black-white-button” style=“color: white” href=“{{ blog_category_url(“Press_Release”) }}”>View All Releases</a>
</div>

Here is the second section:

<div class=“article_list_cta”>
<a class=“black-white-button” style=“color: white” href=“{{ blog_category_url(“Media_Coverage”) }}”>View All Coverage</a>
</div>

I am still getting an error:

Could not resolve function ‘blog_category_url’

SlimSr2003_0-1715694725954.png

I have verified that both the Press_Release and the Media_Coverage tags are in the Newsroom blog.

So I am at a loss as to what is happening. Is there somewhere else in the code of the page that isn’t calling the Newsroom blog? I really don’t know.

Here is the page code:

<!--
templateType: blog_listing
isAvailableForNewContent: true
label: Boilerplate - newsroom listing
screenshotPath: ../images/template-previews/blog-index.png
-->
{% set template_css = “../../css/templates/blog.css” %}
{% extends “./layouts/base.html” %}

{% block body %}
<div class=“column-container”>
{# ----------------------- Header ---------------------- #}
<div class=“blog_header”>
{% module “module_171526232513644” path=“/Filter-Labs-Website/modules/Text Centered Image Tight Left and Right”, label=“Text Centered Image Tight Left and Right” %}
</div>
{# ----------------------- Newsroom Featured Articles ---------------------- #}

<div style=“margin-top: 20px;”>
{% module “module_171527297876861” path=“/Filter-Labs-Website/modules/Recent Newsroom Post Box”, label=“Recent Newsroom Post Box” %}
</div>
</div>
{# ----------------------- Article and Release Lists ---------------------- #}
<div class=“full_width_container_grey”>
<div class=“column-container”>
<div class=“article_release_container”>
<div class=“article_release_subhead”>
<h3>
Articles and Press Releases
</h3>
</div>
<div class=“article_release_list_container”>
<div class=“release_list_containter”>
<div class=“release_list_header”>
<h4>
FilterLabs’ Press Releasees
</h4>
</div>
<div class=“release_list”>
<div>
{% set my_tag_posts = blog_recent_topic_posts(‘default’, ‘Press_Release’, 10) %}
<ul>
{% for post in my_tag_posts %}
<li style=“line-height: 2rem;”><a href=“{{ post.absolute_url }}”>{{ post.title }}</a></li>
{% endfor %}
</ul>
</div>
</div>
<div class=“release_list_cta”>
<a class=“black-white-button” style=“color: white” href=“{{ blog_category_url(“Press_Release”) }}”>View All Releases</a>
</div>
</div>
<div class=“article_list_container”>
<div class=“article_list_header”>
<h4>
FilterLabs in the News
</h4>
</div>
<div class=“article_list”>
<div>
{% set my_tag_posts = blog_recent_topic_posts(‘default’, ‘Media_Coverage’, 10) %}
<ul>
{% for post in my_tag_posts %}
<li style=“line-height: 2rem;”><a href=“{{ post.absolute_url }}”>{{ post.title }}</a></li>
{% endfor %}
</ul>
</div>
</div>
<div class=“article_list_cta”>
<a class=“black-white-button” style=“color: white” href=“{{ blog_category_url(“Media_Coverage”) }}”>View All Coverage</a>
</div>
</div>
</div>
</div>
</div>
</div>

{# ----------------------- News Story Source Request ---------------------- #}

<div class=“column-container”>
<div>
{% module “module_17152861606712” path=“/Filter-Labs-Website/modules/Text Left w Image Form Right”, label=“Text Left w Image Form Right” %}
</div>

{# ----------------------- Events Section ---------------------- #}
<div class=“events_section_container”>
<div>
{% module “module_171529012646220” path=“/Filter-Labs-Website/modules/Centered Text”, label=“Centered Text” %}
</div>
<div>
{% module “module_171528993868617” path=“/Filter-Labs-Website/modules/Event Image and Text Description”, label=“Event Image and Text Description” %}
</div>
<div class=“event_list_cta_container”>
<div class=“event_list_cta”>
<a class=“black-white-button” style=“color: white” href=“{{ blog_tag_url(“Event”, module.blog_post_tag) }}”>View More Events</a>
</div>
</div>
</div>

</div>

{% endblock body %}

Sorry for the back and forth but I appreciate your help.

Thanks

Scott

Hi @SlimSr2003

Thanks for the outcome, happy to help - let me get some other options in some time.

Regards

Hi Humashankar,

I figured out a work around for this. What I did was just put a button to a specific page that has a module that lists out the specific blog tag posts. It’s not exactly what I thought I wanted but I actually like it better. Thanks for your time time and consideration on helping me with this.

Scott

Hi @SlimSr2003

Well done on finding a workaround that suits your needs! Thanks for letting me know and for your appreciation.

Regards

Hi @SlimSr2003

Thanks for sharing your workaround!

Am glad you were able to find a solution that works for you.

Regards

Hi @SlimSr2003

First lets go with this step and will see, whether we can move one level higher.

The error message (Could not resolve function 'blog_category_url) signals that the HubL template engine might not be able to recognize the blog_category_url function within the context of your template.

  • Can you check blog_category_url function is defined or not in the current template or a parent template that is included and it might not be accessible?
  • Check the presence and try to include the necessary HubL libraries or functions blog_category_url which might not be available
  • Look for a parent template - layouts/base.html, that might be extending a core HubSpot template that defines blog_category_url and also ensure the inheritance chain is correct, If blog_category_url is indeed defined in a parent template

Regards