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.

Widgets /

Discuss SilverStripe Widgets.

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

Latest pages widget for children pages


Go to End


5 Posts   2763 Views

Avatar
DyingMuppet

Community Member, 11 Posts

29 May 2010 at 5:01am

Hi guys,

I was wondering how I could modify the Latest pages widget from simon_w to show only the latest couple of children pages for a brief overview (in most cases only the title) of the children pages from a couple of parent pages (note: I don't want every page to have this for its own, Its more a static bar with the latest article titles.)

TIA
Dre

Avatar
joshy

Community Member, 57 Posts

29 May 2010 at 11:39am

Edited: 29/05/2010 11:41am

(OP is referring to http://www.silverstripe.org/Latest-Pages/)

In the widget, the controller DataObject::get currently finds 5 results. Change the '5' to '2' and you've sorted one problem. You'll also want to make sure it only grabs the articles from certain sections, so add ParentID = $this->ID or whatever you need:

$pages = DataObject::get('SiteTree', 'ParentID = '.$this->ID, '`LastEdited` DESC', '', 5);

For issue two - showing a brief overview - you need to edit the template. In the control the anchor tag currently shows <span>$Page.MenuTitle</span>.

You will need to add $Page.Content or $Page.Content.Summary wherever you want it.

Hope this helps.

Edit: re-read what you said and adjusted accordingly

Avatar
DyingMuppet

Community Member, 11 Posts

1 June 2010 at 7:44pm

Thats some very useful info, joshy. Thanks very much.

I'll try to implement this in my site and will keep you in touch.

Grtz, Dre

Avatar
DyingMuppet

Community Member, 11 Posts

2 June 2010 at 2:39am

A little thought:

I guess, from the code Joshy posted that this will show only the latest couple of articles from the parent page I'm on atm.
This is at least a part of what I want to show, maybe I can look into it myself when I have some spare time.
My point actually was to show the same couple of parent pages with the latest children pages on a main sidebar the whole time.

I suppose this has to be some hardcoded ID to use, or via a little bit of control on the CMS side?
For the time being a hardcoded ID wouldn't be much of a problem.

TIA
Dre

Avatar
DyingMuppet

Community Member, 11 Posts

2 June 2010 at 8:20pm

I have changed the LatestPages function a bit to accomplish a part of my needs.
I can now see the children pages on the sidebar when I'm on the parent page, although when I switch to one of the children, the data on the sidebar is gone.

this is the code I have:

	function LatestPages($amount) {
		if($amount == null) { $amount = 3; }
		$pages = DataObject::get('SiteTree', 'ParentID = '.$this->ID, '`LastEdited` DESC', ' ', $amount);
		$return = new DataObjectSet();
		foreach($pages as $page) {
			$versioned = Versioned::get_version("SiteTree", $page->ID, $page->Version);
			$author = Member::get_one("Member", "ID = " . (int)$versioned->AuthorID);
			$parent = Member::get_one('SiteTree', $page->ParentID);
			$return->push(new ArrayData(array('Page' => $versioned, 'Author' => $author, 'Parent' => $parent)));
		}
		return $return;
	}

I'm not yet familiar with implementing a module in the CMS to select pages that should be shown in the sidebar, maybe this would be a much better and easier approach.

Cheers, Dre