From 4f1eb3d22794002b582fbbd21e5e32aa581626a1 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 --- code/model/Blog.php | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/code/model/Blog.php b/code/model/Blog.php index 0ce1b08..43e8c23 100644 --- a/code/model/Blog.php +++ b/code/model/Blog.php @@ -758,7 +758,6 @@ class Blog_Controller extends Page_Controller if ($year) { $this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day); - return $this->render(); } @@ -838,7 +837,7 @@ class Blog_Controller extends Page_Controller if($this->isRSS()) { return $this->rssFeed($this->blogPosts, $tag->getLink()); } else { - return $this->render(); + return $this->render(); } } @@ -882,7 +881,7 @@ class Blog_Controller extends Page_Controller if($this->isRSS()) { return $this->rssFeed($this->blogPosts, $category->getLink()); } else { - return $this->render(); + return $this->render(); } } @@ -1043,7 +1042,37 @@ class Blog_Controller extends Page_Controller 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. * @@ -1128,4 +1157,5 @@ class Blog_Controller extends Page_Controller return false; } } + }