CMS Development

paul5562
Participante

Blog Pagination - "Viewing 1-x of y"

I'm trying to add something to my pagination for my blog. "Viewing 1-10 or 45"

 

So depending on the page of the blog I'm on, this would update. I know the number of posts per page is set in the settings, but I'm having trouble figuring out the HubL that would display this automatically.

 

Any suggestions would be apprecitated. Thanks!

3 Respuestas 3
paul5562
Participante

Blog Pagination - "Viewing 1-x of y"

Thanks for the help. I came up with a solution that seems to work. Maybe there's a way to tighten up the code a little. 

 

What I was looking for was "Viewing 1 - 5 of 45" or "Viewing 11-20 of 52" at the bottom of the blog listing page to go along with the pagination. 

 

My biggest hurdle was figuring out how to pull the "Number of Posts Per Listing Page" value out of the settings. Once I stumbled across that, the rest fell into place.

 

My solution:

{% if current_page_num == 0 %}
    Viewing 1
{% else %}
    Viewing {{ (current_page_num * group.posts_per_listing_page) + 1 }}
{% endif %}
 -
{% if contents.total_count < ((current_page_num * group.posts_per_listing_page) + 1) + (group.posts_per_listing_page -1) %}
    {{ contents.total_count }}
{% else %}
    {{ ((current_page_num * group.posts_per_listing_page) + 1) + (group.posts_per_listing_page -1) }}
{% endif %}
 of
{{ contents.total_count }}
0 Me gusta
natsumimori
Administrador de la comunidad
Administrador de la comunidad

Blog Pagination - "Viewing 1-x of y"

Hi @paul5562 ,

 

Thank you for posting your query in the Community.

I will tag in some of the Community members here: @shivammishra @Chris-M @psdtohubspot could you share your ideas?

psdtohubspot
Asesor destacado

Blog Pagination - "Viewing 1-x of y"

Thanks @natsumimori Sure I will help here

Hi @paul5562 Can you please share a mockup on how it should look like as an example or screenshot.