Sep 28, 2021 5:33 AM
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.
I've included a screengrab of a wireframe for reference.
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
Sep 28, 2021 12:20 PM
Sep 28, 2021 12:32 PM
@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.
Sep 28, 2021 2:18 PM
@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.
Sep 28, 2021 3:32 PM
@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.
Sep 29, 2021 9:44 AM
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.