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   1749 Views

Avatar
mao

Community Member, 3 Posts

21 October 2008 at 1:39am

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

Community Member, 901 Posts

21 October 2008 at 10:05am

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

Community Member, 3 Posts

21 October 2008 at 12:06pm

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

Community Member, 712 Posts

21 October 2008 at 4:01pm

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

Community Member, 3 Posts

22 October 2008 at 4:44am

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"