Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SS3/blog sort order and pagination


Go to End


2039 Views

Avatar
digibrains

Community Member, 130 Posts

15 September 2012 at 10:53am

Edited: 15/09/2012 12:26pm

I'm having an issue getting both sort order and limited pagination both working with latest blog module.

I've extended the BlogHolder and BlogEntry:
WorkHolder extends BlogHolder{}
WorkEntry extends BlogEntry{}

In my _config file I have:

BlogTree::$default_entries_limit=5;

And if I use this in my WorkHolder template, everything works fine. The list limits to 5 entries and the pager at the bottom of the posts works as expected:

<% loop BlogEntries %>

But...

If I change the sort order like this (or whatever I sort by):

<% loop BlogEntries.sort('Sort','ASC') %>

The order changes as expected, but the pagination no longer works. I get the pagination at the bottom of the blog list (e.g., '1 2 Next') but I also get every blog post on every page. So if I have 7 blog posts, I get all seven on page 1 and all seven on page 2.

I also tried doing something like this in my controller:

    public function sortedChildren() {
        $workentry = WorkEntry::get()->sort('Sort', 'ASC');
        return $workentry;
    }

And looping through the sortedChildren, but that has the same issue.

Can someone tell me if this is not possible or what I'm missing or point me in the right direction?

EDIT
Also, adding static $default_sort = 'Sort ASC'; to my WorkEntry class, ordered by SiteTree not SiteTree_Live.
Thanks,
Chris