Jump to:

1840 Posts in 1598 Topics by 557 members

Blog Module

SilverStripe Forums » Blog Module » BlogPagination within BlogEntry

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 899 Views
  • Wilson
    Avatar
    Community Member
    63 Posts

    BlogPagination within BlogEntry Link to this post

    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

  • jaredkipe
    Avatar
    Community Member
    16 Posts

    Re: BlogPagination within BlogEntry Link to this post

    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.

  • badjedi
    Avatar
    Community Member
    25 Posts

    Re: BlogPagination within BlogEntry Link to this post

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

    Thanks in advance..

  • Wilson
    Avatar
    Community Member
    63 Posts

    Re: BlogPagination within BlogEntry Link to this post

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

       }

    899 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.