CMS Development

SD_dev
Member

How to get current "tag" of blog listing page and check if it is the first page

SOLVE

I am trying to write conditional logic to display a popular posts section on my blog listings pages.

 

I want to display this on the "tag" listing pages. I only want to display it on the 1st in the series, so any pagination /2, /3, etc will not feature the popular post section.

 

I see that I can do this by splitting up the url of the page:

 

mysite.com/blog/tag/accounting-processes

 

To determine the correct tag "accounting-processes" and if it is the 1st in the series.

 

But this seems like a silly way to do this, there is surely a "tag page" variable? which would tell me the "tag" of the current listing page and give me a way to distinguish if this is the 1st page in the series?

 

I tried checking 

https://developers.hubspot.com/docs/cms/hubl/variables

 

But I cannot find any appropriate variable.

 

Does anyone know how I could target this? Or will I have to just work from the page url.

 

Thank you

 

 

0 Upvotes
1 Accepted solution
Indra
Solution
Guide | Elite Partner
Guide | Elite Partner

How to get current "tag" of blog listing page and check if it is the first page

SOLVE

@Jaycee_Lewis thanks for mentioning.

 

Hi @SD_dev,

 

There are a few tags to check what type of page it is.

 

{% if topic %}
  {# topic listing page #}
{% elif blog_author %}
  {# blog author page #}
{% else %}
  {# listing page #}
{% endif %}

 

 

To get the current page number, you can use the tag {{ current_page_num }}. For documentation, see hubl variables. You can check on the following:

 

{% if current_page_num == 1 %}
  {# This is the first page #}
{% endif %}

 

 

The only thing you need to do, is combining the two.

 

 

{% if topic && current_page_num == 1 %}
  {# First topic listing page #}
{% endif %}

 


Vet Digital - The Growth Agency | HubSpot Solutions Partner Agency

Did my post solve your question? Help the community by marking it as a solution

View solution in original post

6 Replies 6
Indra
Solution
Guide | Elite Partner
Guide | Elite Partner

How to get current "tag" of blog listing page and check if it is the first page

SOLVE

@Jaycee_Lewis thanks for mentioning.

 

Hi @SD_dev,

 

There are a few tags to check what type of page it is.

 

{% if topic %}
  {# topic listing page #}
{% elif blog_author %}
  {# blog author page #}
{% else %}
  {# listing page #}
{% endif %}

 

 

To get the current page number, you can use the tag {{ current_page_num }}. For documentation, see hubl variables. You can check on the following:

 

{% if current_page_num == 1 %}
  {# This is the first page #}
{% endif %}

 

 

The only thing you need to do, is combining the two.

 

 

{% if topic && current_page_num == 1 %}
  {# First topic listing page #}
{% endif %}

 


Vet Digital - The Growth Agency | HubSpot Solutions Partner Agency

Did my post solve your question? Help the community by marking it as a solution
SD_dev
Member

How to get current "tag" of blog listing page and check if it is the first page

SOLVE

Hey Indra, thanks for your answer that's really helped!

I'm wondering now how to output the current "Tag" of the listing page as well. If I find a solution I will post.

0 Upvotes
SD_dev
Member

How to get current "tag" of blog listing page and check if it is the first page

SOLVE

Okay, for anyone following, that is as simple as writing:

 

{{ tag }}
Jaycee_Lewis
Community Manager
Community Manager

How to get current "tag" of blog listing page and check if it is the first page

SOLVE

Hi, @SD_dev 👋 Thanks for reaching out! Hey, @Indra @Oezcan, do you have any tips for @SD_dev? Or thoughts on other ways they can think about their project?

 

Best,

Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
felixmacaspac
Participant

How to get current "tag" of blog listing page and check if it is the first page

SOLVE

Hey @SD_dev maybe the blog_page_link is the function you are looking for.

 

https://developers.hubspot.com/docs/cms/hubl/functions#blog-page-link

SD_dev
Member

How to get current "tag" of blog listing page and check if it is the first page

SOLVE

Thanks but i'm not looking to pull any URLs, just want to get the current listing page "tag" and the pagination level.

0 Upvotes