Jump to:

5450 Posts in 1672 Topics by 1197 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: 2027 Views
  • Daimz
    Avatar
    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:
    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.

  • joshy
    Avatar
    Community Member
    57 Posts

    Re: reverse order of posts Link to this post

    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

  • Daimz
    Avatar
    Community Member
    36 Posts

    Re: reverse order of posts Link to this post

    That worked a charm, thanx so much.

    2027 Views
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.