1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » "Forward" and "Back" or "Prev" and "Next" Buttons
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1504 Views |
-
"Forward" and "Back" or "Prev" and "Next" Buttons

23 April 2009 at 7:40am
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.
-
Re: "Forward" and "Back" or "Prev" and "Next" Buttons

23 April 2009 at 12:37pm Last edited: 23 April 2009 5:13pm
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.
-
Re: "Forward" and "Back" or "Prev" and "Next" Buttons

24 April 2009 at 10:32pm
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() : '';
} -
Re: "Forward" and "Back" or "Prev" and "Next" Buttons

26 April 2012 at 8:56pm
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/
| 1504 Views | ||
|
Page:
1
|
Go to Top |


