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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[FIXED] "Previous or Next Buttons" example not fully working

Go to End

5 Posts   2095 Views


Community Member, 49 Posts

2 September 2010 at 7:57pm

Edited: 03/09/2010 8:51pm

Using the exact same code as on:

The example on here worked beautifully for cycling through my News pages in the news section.

However when I use the same page template ( again for the Publication and Events section the previous or next buttons fail to work. This is my site structure...

Seems odd when i have used exactly the same code as the example and same page template (


Community Member, 181 Posts

3 September 2010 at 9:09am

Hi Johan,

What do you mean by "fail to work"? Do the links show at all and if so where do they link to?

Have you put the code in your Page_Controller or ArticlePage_Controller?

This is a standard addition to my Page.php and using it without issue so I'm sure we can figure this out.


Community Member, 90 Posts

3 September 2010 at 11:47am

i have got this function works quite well for me?!
not sure why it fails on yours.
Maybe provide some code of your ( and template .ss could be helpful.


Community Member, 49 Posts

3 September 2010 at 7:23pm

Edited: 03/09/2010 7:52pm

1. Only in the news pages do they work (using ArticlePage).

2. Publications and Events the paging does not show at all (again using ArticlePage).

Code ArticlePage.php:

 * Defines the ArticlePage page type
class ArticlePage extends Page {
   static $db = array(
		'Date' => 'Date',
		'Author' => 'Text',	  
   static $has_one = array(
   static $icon = "themes/tutorial/images/treeicons/news";
   	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
		// $fields->addFieldToTab('Root.Content.Main', new DateField('Date'), 'Content');
		$datefield = new DateField('Date');
		$datefield->setConfig('showcalendar', true);
		$datefield->setConfig('showdropdown', true);
		$datefield->setConfig('dateformat', 'dd/MM/YYYY');
		$fields->addFieldToTab('Root.Content.Main', $datefield, 'Content');

		return $fields;

class ArticlePage_Controller extends Page_Controller {

	function LatestNews($num=3) {
		$news = DataObject::get_one("NewsHolder");
		return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;

 // ************ Previous or Next Buttons *************
 public function nextPager() {
  $where = "ParentID = ($this->ParentID + 0) AND Sort > ($this->Sort + 0 )";
  $pages = DataObject::get("SiteTree", $where, "Sort", "", 1);
  if($pages) {
   foreach($pages as $page) {
    return $page;
 public function previousPager() {
  $where = "ParentID = ($this->ParentID + 0) AND Sort < ($this->Sort + 0)";
  $pages = DataObject::get("SiteTree", $where, "Sort DESC", "", 1);
  if($pages) {
   foreach($pages as $page) {
    return $page;


  <div class="paging">
	 <% if previousPager %>
	  <p class="previous"><a href="$previousPager.URLSegment">Previous</a></p>
	 <% end_if %>
	 <% if nextPager %>
	  <p class="next"><a href="$nextPager.URLSegment">Next</a></p>
	 <% end_if %>

Many thanks.


Community Member, 49 Posts

3 September 2010 at 8:50pm

A programmer on IRC has found the issue.

The reason it fails is because all the articles have the same date.

Changed the dates now work.