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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

reverse order of posts


Go to End


3 Posts   2834 Views

Avatar
Daimz

Community Member, 36 Posts

4 August 2009 at 11:48pm

Currently I have a portfolio page and it shows all the images except the most recently added page is displayed as the last image on the page. (i uses pages and call them using 'childern' in to the portfolio.) I want it so its the very first image and as you scroll down the images get older in order of when they were created.

This is how I am calling them:
PortfolioHolder.ss

    <% control Children %>
		<div id="port_box">
			<span>$portImage</span>
			<span class="port_type">
			<span class="port_title_type">Client:</span> $Client</span>
			<span class="port_type"><span class="port_title_type">Project:</span> $Task</span>
			<span class="port_type"><span class="port_title_type">Role:</span> $Role</span>
			<span class="port_type"><span class="port_title_type">Summary:</span> $Content</span>
		</div>
    <% end_control %>

PortfolioHolder.php
<?php
/**
 * Defines the PortfolioHolder page type
 */
class PortfolioHolder extends Page {
   static $db = array(
   );
   static $has_one = array(
   );
   
   static $allowed_children = array('PortfolioPage');
   
   static $icon = "themes/tutorial/images/treeicons/news";
}
 
class PortfolioHolder_Controller extends Page_Controller {



function rss() {
  $rss = new RSSFeed($this->Children(), $this->Link(), "The coolest news around");
  $rss->outputToBrowser();
}
function init() {
   RSSFeed::linkToFeed($this->Link() . "rss");	
   parent::init();
}
 
}
 
?>

can anyone help please?
Thanx in advance.

Avatar
joshy

Community Member, 57 Posts

5 August 2009 at 5:46am

Edited: 05/08/2009 5:47am

Hiya,

You need to create a controlled method (in the PortfolioHolderController in this example) to handle this in reverse. Something like:

function ReverseChildren()
{
         $reversed = $this->Children();
         $reversed->sort('Created', 'DESC');
         return $reversed;
}

In that code we have created a new DataObjectSet called $reversed and given it the values that 'Children' had (ie, all the child pages). We then sorted it by the field 'Created' descending so the newest is first. You could sort by any field - for instance Title ASC (to get it in alphabetical order of the title).

In the template you need to call that control:

<% control ReverseChildren %>
         <!-- do all your children stuff the same as normal -->
<% end_control %>

I hope this helps,

Josh

Avatar
Daimz

Community Member, 36 Posts

5 August 2009 at 11:15pm

That worked a charm, thanx so much.