From dae2ba0e5f3480cf029b99fbf427e8e280a8c431 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Wed, 3 May 2017 11:44:37 +1000 Subject: [PATCH] add meta links for previous and next pages in pagination --- src/Model/BlogController.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Model/BlogController.php b/src/Model/BlogController.php index 47e203a..445be05 100644 --- a/src/Model/BlogController.php +++ b/src/Model/BlogController.php @@ -3,6 +3,7 @@ namespace SilverStripe\Blog\Model; use PageController; +use SilverStripe\Control\Director; use SilverStripe\Control\RSS\RSSFeed; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\FieldType\DBDatetime; @@ -432,6 +433,39 @@ class BlogController extends PageController return $posts; } + + /** + * Returns the absolute link to the next page for use in the page meta tags. This helps search engines + * find the pagination and index all pages properly. + * + * @example "<% if $PaginationAbsoluteNextLink %><% end_if %>" + * + * @return string + */ + public function PaginationAbsoluteNextLink() + { + $posts = $this->PaginatedList(); + if ($posts->NotLastPage()) { + return Director::absoluteURL($posts->NextLink()); + } + } + + /** + * Returns the absolute link to the previous page for use in the page meta tags. This helps search engines + * find the pagination and index all pages properly. + * + * @example "<% if $PaginationAbsolutePrevLink %><% end_if %>" + * + * @return string + */ + public function PaginationAbsolutePrevLink() + { + $posts = $this->PaginatedList(); + if ($posts->NotFirstPage()) { + return Director::absoluteURL($posts->PrevLink()); + } + } + /** * Displays an RSS feed of blog posts. *