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.

Archive /

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

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

What's new on my page


Reply


3 Posts   2244 Views

Avatar
tomasulej

Community Member, 2 Posts

23 July 2007 at 2:31am

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

Avatar
Willr

Forum Moderator, 5513 Posts

23 July 2007 at 10:00am

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.

Avatar
elijahlofgren

Google Summer of Code Hacker, 222 Posts

25 July 2007 at 9:21am

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 [url]http://new.elijahlofgren.com/[/url]
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 [url=http://doc.silverstripe.com/doku.php?id=devmode]devmode[/url] 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 [url=http://doc.silverstripe.com/doku.php?id=tutorial:1-building-a-basic-site#changing_the_page_type_of_the_home_page]Changing the page type of the Home page[/url]

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

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

I've posted an example of how to show the latest updates
[url=http://doc.silverstripe.com/doku.php?id=rssfeed#example_of_showing_the_10_most_recently_updated_pages]RSSFeed: Example of showing the 10 most recently updated pages[/url]
Here is that code running: [url]http://new.elijahlofgren.com/home/rss[/url]

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

Hope this helps,

Elijah Lofgren