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.

Archive /

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

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

What's new on my page


Go to End


3 Posts   2732 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, 5523 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 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