Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » reverse order of posts

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

Page: 1
Go to End
Author Topic: 2104 Views
  • Daimz
    Community Member
    36 Posts

    reverse order of posts Link to this post

    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:

    <% control Children %>
          <div id="port_box">
             <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>
    <% end_control %>


    * 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");
    function init() {
    RSSFeed::linkToFeed($this->Link() . "rss");   



    can anyone help please?
    Thanx in advance.

  • joshy
    Community Member
    57 Posts

    Re: reverse order of posts Link to this post


    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,


  • Daimz
    Community Member
    36 Posts

    Re: reverse order of posts Link to this post

    That worked a charm, thanx so much.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.