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

Latest article from diferent article holders?


Go to End


5 Posts   2108 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
bummzack

Community Member, 904 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 http://doc.silverstripe.com/doku.php?id=recipes:displaying_five_latest_pages_from_multiple_pagetypes 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"