Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » widget to return last news title

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1063 Views
  • ojalà
    Avatar
    Community Member
    87 Posts

    widget to return last news title Link to this post

    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?

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: widget to return last news title Link to this post

    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.

  • ojalà
    Avatar
    Community Member
    87 Posts

    Re: widget to return last news title Link to this post

    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;
    }

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: widget to return last news title Link to this post

    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?

  • ojalà
    Avatar
    Community Member
    87 Posts

    Re: widget to return last news title Link to this post

    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..

    1063 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.