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, Ed, biapar, Willr, Ingo, swaiba

"Forward" and "Back" or "Prev" and "Next" Buttons

Go to End

4 Posts   2989 Views


Community Member, 165 Posts

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.


Community Member, 165 Posts

23 April 2009 at 12:37pm

Edited: 23/04/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.


Community Member, 26 Posts

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() : '';


Community Member, 19 Posts

26 April 2012 at 8:56pm

For anyone else who stumbles onto this post, check out this excellent tutorial