CMS Development

JKeith
Mitglied

Sorting all blog posts

lösung

Hi,

 

I was easily able to find a way to sort my blog posts by most recently updated using sort:

{% for content in contents|sort(True, False, 'updatedDateTime') %}

 

However, it only sorts the posts in batches according to the pagination, I guess because of lazy loading? The first page is the 12 most recently published posts sorted by the update time, then the second page is the next 12 most recently published sorted by the update time, and so on.  I tried setting a variable before the loop, as in 

{% set sorted_contents = contents|sort(True, False, 'updatedDateTime') %}

and then pass sorted_contents into the for loop, but it didn't work. 

 

Is there a way to sort the entire contents array outside of pagination/lazy loading? Thanks in advance.

0 Upvotes
1 Akzeptierte Lösung
Kevin-C
Lösung
Trendsetter/-in | Partner
Trendsetter/-in | Partner

Sorting all blog posts

lösung

Hey @JKeith 

You could use the blog posts API.

Your request could sort parameter to do exactly this!

KevinC_0-1642133896610.png

Ideally this would be returned from a serverless function so the API key isn't exposed.

 

 

EDIT:
This be rather simple using Vue.js!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev

Lösung in ursprünglichem Beitrag anzeigen

1 Antwort
Kevin-C
Lösung
Trendsetter/-in | Partner
Trendsetter/-in | Partner

Sorting all blog posts

lösung

Hey @JKeith 

You could use the blog posts API.

Your request could sort parameter to do exactly this!

KevinC_0-1642133896610.png

Ideally this would be returned from a serverless function so the API key isn't exposed.

 

 

EDIT:
This be rather simple using Vue.js!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev