CMS Development

JimWib
Member

Multiple Blog filters with pagination - is it possible?

I'm creating a blog which posts need to be filtered 3 ways, the types themselves are family arbitrary but I'll list them for clarity and hopefully someone will know of a way to achieve this level of categorisation with Hubspot blogs as tags feels a little limited at the minute but could potentially still work. 

 

Content Type

  • News
  • Interview
  • Case Study
  • Press Release

Sector

  • Sports
  • Entertainment
  • Live

Location

  • US
  • UK
  • Africa
  • Middle East

I've included a screengrab of a wireframe for reference.

Screenshot 2021-09-22 at 10.32.08.png

So a post has a content type, has many sections and has many locations. I then want to be able to paginate the results. Essentially they way the /tag/[TAG-SLUG] routes work, but with multiple tags

 

Using the example here https://community.hubspot.com/t5/CMS-Development/Custom-Blog-Listing/m-p/498408

 

Its possible to filter by multiple tags at once, however it needs to be done using the blog/all route where we are limited to 200 posts which we then can't paginate so it feels like it's not a scalable approach.

 

I appreciate your help on this

0 Upvotes
5 Replies 5
albertsg
Guide

Multiple Blog filters with pagination - is it possible?

If you can have all content in a JSON somewhere in your page, then I believe that's the best solution.

 

Another option (but also limited) would be to get the content based on a tag instead of the "general" content that is limited to 200 elements.

 

By using  blog_recent_tag_posts you could get 100 posts that have a specific tag. Then you can use this data in your listing page.

 

Imagine the following scenario:

 

You have 4 categories with 60, 40, 70, 80 articles each (total of 250 posts). If you get the "default" 200 articles, you will be missing 50 articles in your listing.

But if you filter by tag using blog_recent_tag_posts for each category, then you will be able to display all articles in your category (unless a category has +100 articles).

 

This is not as good as having all your content in a JSON file, but it might be a solution if you don't have hundreds of articles per category.



Did my answer help you? Mark it as a solution

You also connect with me on LinkedIn or Twitter

JimWib
Member

Multiple Blog filters with pagination - is it possible?

@stefen Thanks for your thoughts on this. 

 

In terms of client side ajax , would you just request the normal html version of the page and parse the response for the posts? In that case I can probably output the posts to JSON in the htmlm, request the page then find the JSON of my posts parse and filter then output to html quite easily...  Or is there part of an API endpoint I don't know about? I looked at the Server Blog API as an option and that didnt look like it supports filtering by tags.  

0 Upvotes
stefen
Key Advisor | Partner
Key Advisor | Partner

Multiple Blog filters with pagination - is it possible?

@JimWib yeah, I would just request the normal version. Putting all the data you need in JSON somewhere on the page might make things easier for sure.

You could definitely just roll your own server side blog with the CMS endpoints. However, I don't see anything in there to request batches of posts by tag/topic so probably not worth the extra hassle.

Stefen Phelps, Community Champion, Kelp Web Developer
dennisedson
HubSpot Product Team
HubSpot Product Team

Multiple Blog filters with pagination - is it possible?

@stefen , @piersg  do you all have any advice for this?

0 Upvotes
stefen
Key Advisor | Partner
Key Advisor | Partner

Multiple Blog filters with pagination - is it possible?

@dennisedson @JimWib one approach you could take is make each one of those a tag/topic and use client side AJAX to populate the results from each of the paginated tag URLs. You could then paginate and filter as you please without too much performance downside.

 

For example, if someone wants to filter by Press Release you would request the posts from `/tag/press-release/page/1` and then the next post button would get posts from the page 2 url. If someone were to filter by multiple tags you would make multiple AJAX requests and combine the results before printing to DOM. Combining the results would require a little bit of logic to filter out any posts not in both tags.

Stefen Phelps, Community Champion, Kelp Web Developer