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

BlogPagination within BlogEntry


Go to End


4 Posts   1714 Views

Avatar
Wilson

Community Member, 63 Posts

28 June 2011 at 5:05pm

Hi Carlos and others,

I'm attempting to paginate a blog, then add the navigation and pagination to the BlogEntry template. For this particular client, the BlogHolder redirects to the first child and there is no BlogTree.

I'm not having much joy yet. I've tried wrapping <% control Parent... Top... BlogTree... BlogHolder in the template but I'm not getting any pagination.

I do see that BlogEntry extends Page and BlogPagination is within BlogTree, so I attempted an alternative setup to use BlogTree -> BlogHolder -> BlogEntry, but still was unable to find the right syntax to get the BlogPagination in BlogEntry.

I also tried a function in the model to return getParent->getParent.

Has anyone done this before?

I very much appreciate any advice.

Thanks!
Wilson

Avatar
jaredkipe

Community Member, 16 Posts

15 July 2011 at 12:04pm

Off the top of my head I would guess that in BlogEntry a section like <% control ChildrenOf(/blog/) %> will give you a set of all the children. (assuming the BlogHolder's url is /blog/)

But that won't really get you pagination, just all of them at once.

The template file, BlogPagination, relies on DataObjectSet's NextLink and PrevLink in sophisticated ways.

Avatar
badjedi

Community Member, 25 Posts

27 July 2011 at 12:22am

I am trying to figure this out too. Any ideas?

Thanks in advance..

Avatar
Wilson

Community Member, 63 Posts

27 July 2011 at 2:28am

Turns out BlogEntry extends Page, so you can just treat BlogEntries as pages, i.e. using the PrevNextPage function (that's in another forum post).

public function PrevNextPage($Mode = 'next') {
if($Mode == 'next'){
$Where = "ParentID = ($this->ParentID) AND Sort > ($this->Sort)";
$Sort = "Sort ASC";
} elseif($Mode == 'prev') {
$Where = "ParentID = ($this->ParentID) AND Sort < ($this->Sort)";
$Sort = "Sort DESC";
} else {
return false;
}

return DataObject::get("SiteTree", $Where, $Sort, null, 1);

}