21301 Posts in 5735 Topics by 2603 members
General Questions
SilverStripe Forums » General Questions » [FIXED] "Previous or Next Buttons" example not fully working
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1340 Views |
-
[FIXED] "Previous or Next Buttons" example not fully working

2 September 2010 at 7:57pm Last edited: 3 September 2010 8:51pm
Using the exact same code as on: http://doc.silverstripe.org/recipes:previousornext
The example on here worked beautifully for cycling through my News pages in the news section.
However when I use the same page template (ArticlePage.cc/php) 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 (ArticlePage.cc/php)
-
Re: [FIXED] "Previous or Next Buttons" example not fully working

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.
-
Re: [FIXED] "Previous or Next Buttons" example not fully working

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 (ArticlePage.cc/php) and template .ss could be helpful. -
Re: [FIXED] "Previous or Next Buttons" example not fully working

3 September 2010 at 7:23pm Last edited: 3 September 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:
<?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;
}
}
}}
?>
ArticlePage.ss
<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 %>
</div>Many thanks.
-
Re: [FIXED] "Previous or Next Buttons" example not fully working

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.
| 1340 Views | ||
|
Page:
1
|
Go to Top |


