From 3864a78ab59d39ed625ef16413905398517b1604 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sun, 16 May 2010 01:10:24 +0000 Subject: [PATCH] FEATURE: added NextBlogEntry() and PreviousBlogEntry() functions to allow getting the next / previous posts by date in the template using $NextBlogEntry and $PreviousBlogEntry respectively --- code/BlogEntry.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/code/BlogEntry.php b/code/BlogEntry.php index 10499aa..def075d 100644 --- a/code/BlogEntry.php +++ b/code/BlogEntry.php @@ -188,9 +188,39 @@ class BlogEntry extends Page { static function allow_wysiwyg_editing() { self::$allow_wysiwyg_editing = true; } + + + /** + * Get the previous blog entry from this section of blog pages. + * + * @return BlogEntry + */ + function PreviousBlogEntry() { + return DataObject::get_one( + 'BlogEntry', + "\"SiteTree\".\"ParentID\" = '$this->ParentID' AND \"BlogEntry\".\"Date\" < '$this->Date'", + true, + 'Date DESC' + ); + } + + /** + * Get the next blog entry from this section of blog pages. + * + * @return BlogEntry + */ + function NextBlogEntry() { + return DataObject::get_one( + 'BlogEntry', + "\"SiteTree\".\"ParentID\" = '$this->ParentID' AND \"BlogEntry\".\"Date\" > '$this->Date'", + true, + 'Date ASC' + ); + } } class BlogEntry_Controller extends Page_Controller { + static $allowed_actions = array( 'index', 'trackbackping',