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

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

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

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

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

Hi, @SD_dev :waving_hand: 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

@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 %}

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.

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

{{ tag }}