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

Working Pagination sample for ArticlesHilder from tutorial

Go to End

3 Posts   1547 Views


Community Member, 5 Posts

12 April 2011 at 11:19pm
Not completed

Tutorial for AtricleHolder

Can some one write "recommended" and right code?


Community Member, 344 Posts

12 April 2011 at 11:29pm

Edited: 12/04/2011 11:43pm


function Articles($pagination=true) {
	if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
	$Limit = $pagination==true ? (int)$_GET['start'].",5" : null;

	$Articles = DataObject::get(
			'Date DESC',
	return !empty($Articles) ? $Articles : false;

And in the template...

<% if Articles.MoreThanOnePage %>
<p style="text-align:center;">
	<a href="$Articles.PrevLink" class="left"<% if Articles.PrevLink %><% else %> style="visibility:hidden;"<% end_if %>>&lt;&lt; Previous</a>
	<% control Articles.Pages %>
	<% if CurrentBool %>
	<% else %>
	<a href="$Link" title="$PageNum">$PageNum</a>
	<% end_if %>
	<% end_control %>
	<a href="$Articles.NextLink" class="right"<% if Articles.NextLink %><% else %> style="visibility:hidden;"<% end_if %>>Next &gt;&gt;</a>
<% end_if %>


Community Member, 5 Posts

13 April 2011 at 12:46am

Tnx Devlin.

I thought it would be more elegant:)