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

Latest article from diferent article holders?


Reply

5 Posts   1723 Views

Avatar
mao

21 October 2008 at 1:39am Community Member, 3 Posts

Example site look:
Start
-first category
--1subcatergory (article holder)
--2subcategrory (article holder)
--3subcategory (article holder)
-second category
--1subcatergory (article holder)
--2subcategrory (article holder)
--3subcategory (article holder)
...
My problem is how to show in 1category or 2category latest articles (ArticlePage) from their (only their) subcategories?

Avatar
banal

21 October 2008 at 10:05am Community Member, 901 Posts

Hi

You could simply use something like this in your template:

<% control Children.First %>
... output something, eg. $Title
<% end_control %>

This will output the first Child of the current page. The last one could be accessed with Children.Last

Avatar
mao

21 October 2008 at 12:06pm Community Member, 3 Posts

i was thinking about some sort of function like in [url]http://doc.silverstripe.com/doku.php?id=recipes:displaying_five_latest_pages_from_multiple_pagetypes[/url] or in second tutorial but im not sure exacly how to write it?

Avatar
Hamish

21 October 2008 at 4:01pm Community Member, 712 Posts

In the category pages:

function Latest() {
return DataObject::get_one("ArticleHolder", "ParentID = $this->ID", "Date DESC");
}

Call in your template:

<% if Latest %>
<% control Latest %>
<h3>$Latest.Title</h3>
<div>$Latest.Content</div>
<% end_control %>
<% end_if %>

Avatar
mao

22 October 2008 at 4:44am Community Member, 3 Posts

ok thanks for reply
i make this in hard way
All subcategory have now their own holders and i use then function from recipe "five lates pages"