Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » "Forward" and "Back" or "Prev" and "Next" Buttons

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 1975 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    "Forward" and "Back" or "Prev" and "Next" Buttons Link to this post

    Is there an easy way to add buttons or links to move between Blog Entries while in a Blog Entry view? As it is now you always have to go back to the Blog Holder page to select a different Entry to read. Word Press and other Blog engines have this feature and my client is asking for it as well.

    I can probably write it myself but I don't like messing with core code in case I want to upgrade.

  • micahsheets
    Avatar
    Community Member
    164 Posts

    Re: "Forward" and "Back" or "Prev" and "Next" Buttons Link to this post

    How do I compare Dates for blog entries?

       protected function adjacentBlogEntry($dir){
          if ($this->ClassName == "BlogEntry"){
             $t = $dir == "next" ? "<" : ">";
             $obj = DataObject::get_one("Page", "`ParentID` = $this->ParentID AND Date $t '$this->Date'");
             return ($obj) ? $obj->URLSegment : false;
          }
          else return false;
       }
       
    This function works for Next sort of but prev always gives the same blog post.

    Since a date field in mysql is date and time I suppose that maybe I cannot compare Date and '$this->Date' in a WHERE statement.

    All I am trying to do here is have it give me the URLSegment of the blog entry that has a Date before or after the current Date.

  • mango
    Avatar
    Community Member
    26 Posts

    Re: "Forward" and "Back" or "Prev" and "Next" Buttons Link to this post

    The following works for me but I'm sure someone else can come up with a better way:

       function getOlderBlogEntryLink() {
          $obj = DataObject::get_one("Page", "`ParentID` = $this->ParentID AND Date < '$this->Date'", true, 'Date DESC');
          return ($obj) ? $obj->Link() : '';
       }
       function getNewerBlogEntryLink() {
          $obj = DataObject::get_one("Page", "`ParentID` = $this->ParentID AND Date > '$this->Date'", true, 'Date');
          return ($obj) ? $obj->Link() : '';
       }

  • greenpea
    Avatar
    Community Member
    19 Posts

    Re: "Forward" and "Back" or "Prev" and "Next" Buttons Link to this post

    For anyone else who stumbles onto this post, check out this excellent tutorial http://www.ssbits.com/tutorials/2009/creating-previous-and-next-buttons-on-a-page/

    1975 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.