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

widget to return last news title


Go to End


5 Posts   1441 Views

Avatar
ojalà

Community Member, 87 Posts

10 October 2008 at 3:11am

Hi!
I look in widget area and I don't find my widget: I need a widget that return my last 4 title of news.
So I have a news pages where I have news title and some breaf description. I want a widget that in homepage return the title of last 5 news. Is this possible? Exist a widget to do thah?

Avatar
Liam

Community Member, 470 Posts

10 October 2008 at 6:18am

This is explained in tutorial 2.

http://doc.silverstripe.com/doku.php?id=tutorial:2-extending-a-basic-site#showing_the_latest_news_on_the_homepage

Just modify it to not show links, if you're only interested in the title.

Doubt there is a widget for it, since it is covered here but maybe there is.

Avatar
ojalà

Community Member, 87 Posts

15 October 2008 at 2:45am

HI!
thanks for your answer but I can't see news.I copy all the code, but something is wrong..

<ul id="NewsList">
<% control LatestNews %>
<li class="newsDateTitle"><a href="$Link" title="Read more on &quot;{$Title}&quot;">$Title</a></li>
<li class="newsDateTitle">$Date.Nice</li>
<li class="newsSummary">$Content.FirstParagraph<a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a></li>
<% end_control %>
</ul>

I think the problem is link to LatestNews because I can't enter in <% control LatestNews %>.
In function get_one I have "ArticleHolder". this is a link to ArticleHolder.php?My news are in ARticlePage so I don't understand..can you help me?

function LatestNews($num=5) {
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
}

Avatar
Liam

Community Member, 470 Posts

15 October 2008 at 3:59am

Well you need to change "ArticleHolder" and "ArticlePage" in the LatestNews function to whatever page types you've created. Generally speaking you should have a page that holds all the news (holder page), and then individual news entries. Are these named the same as in the function?

Are you saying no information is returned at all? Everything is blank?

Avatar
ojalà

Community Member, 87 Posts

15 October 2008 at 4:55am

Yes, the name of page that memorize article are the same (ArticlePage and ArticleHolder) and the name of new page type where I copy LatestNews is NewsPage.php (and the relative template NeswPage.ss). Everything is blank..