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.

Blog Module

Discuss the Blog Module.

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

BlogPagination within BlogEntry


Reply

4 Posts   926 Views

Avatar
Wilson

28 June 2011 at 5:05pm Community Member, 63 Posts

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

15 July 2011 at 12:04pm Community Member, 16 Posts

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

27 July 2011 at 12:22am Community Member, 25 Posts

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

Thanks in advance..

Avatar
Wilson

27 July 2011 at 2:28am Community Member, 63 Posts

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);

   }