Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » What's new on my page

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2186 Views
  • tomasulej
    Avatar
    Community Member
    2 Posts

    What's new on my page Link to this post

    Hello,

    All page types on my site have $Date field and I would like to have page "What's new on my site" where all pages will be displayed according to $Date. Do you have any idea how to do that? And how to export that list as RSS for my subscribers?

    Thank you very much

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: What's new on my page Link to this post

    Tutorial 2 covers both of those, you should be able to follow that and get a general idea of what to do - http://doc.silverstripe.com/doku.php?id=tutorial:2-extending-a-basic-site.

  • elijahlofgren
    Avatar
    Google Summer of Code Hacker
    222 Posts

    Re: What's new on my page Link to this post

    Hi tomasulej,

    > All page types on my site have $Date field and I would like to have page "What's new on my site" where all pages will be displayed according to $Date. Do you have any idea how to do that?

    Here is what I just implemented on http://new.elijahlofgren.com/
    1. Put the following code in a HomePage.php file and upload it to mysite/code:

    /**
    * Defines the HomePage page type
    */

    class HomePage extends Page {
       static $icon = "mysite/images/treeicons/home";
       static $db = array(
       );
       static $has_one = array(
       );
    }

    class HomePage_Controller extends Page_Controller {

       function RecentlyUpdated() {
          $pages = DataObject::get("Page", "", "LastEdited DESC", "", 10);
          $doSet = new DataObjectSet();
          foreach($pages as $key => $data) {
             $title = $data->Title;
             $record = array(
                'Link' => $data->Link(),
                'Title' => $title,
                'Date' => $data->LastEdited
             );
             $doSet->push(new ArrayData($record));
          }
          return $doSet;
       }

    }


    Note: You'll probably want to change "'Date' => $data->LastEdited" to "'Date' => $data->Date" and "LastEdited DESC" to "Date DESC"

    2. Put the following code in a HomePage.ss file and upload it to mysite/templates/Layout
    [html]
    <h2>$Title</h2>

    $Content

    <h3>Most Recent Updates</h3>
    <ul>
       <% control RecentlyUpdated %>
          <li>
          $Date - <a href="$Link">$Title</a>
          </li>
       <% end_control %>
    </ul>

    $Form
    $PageComments
    [/html]
    3. Go to /db/build/ (you may need to put your site in devmode in order to allow db/build to be run (sometimes logging in with the your password doesn't work))
    4. Go to /admin?flush=1 and change your home page to have Page Type "HomePage" as described here Changing the page type of the Home page

    You can see this code running here: http://new.elijahlofgren.com/

    > And how to export that list as RSS for my subscribers?

    I've posted an example of how to show the latest updates
    RSSFeed: Example of showing the 10 most recently updated pages
    Here is that code running: http://new.elijahlofgren.com/home/rss

    Note: You'll probably want to change "LastEdited DESC" to "Date DESC"

    Hope this helps,

    Elijah Lofgren

    2186 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.