Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » SOLVED! how to get Latest News on custom page and homepage

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 459 Views
  • w1l
    Avatar
    Community Member
    13 Posts

    SOLVED! how to get Latest News on custom page and homepage Link to this post

    Hi there

    I currently have latest news on the homepage, which is great, i want it on another page as well.

    I've created a custom page type with a Controller 'HomePageNoIntro.php' and a Template 'HomePageNoIntro.ss'

    I've copied the code from HomePage.php and HomePage.ss and placed in the new pages.

    Which creates the container, but no articles ... I'm sure the issue is in the Controller page :mysite/code/HomePageNoIntro.php

    <?php
    class HomePageNoIntro extends Page {
    }

    class HomePageNoIntro_Controller extends Page_Controller {
    // ...
       public function LatestNews($num=5) {
        $holder = ArticleHolder::get()->First();
        return ($holder) ? ArticlePage::get()->filter('ParentID', $holder->ID)->sort('Date DESC')->limit($num) : false;
       }
    }


    Do i need a different function from the HomePage.php function? - i've tried just changing the function name (LatestNewsB) - and updating the template ... but this did nothing?

    I'm confused - surely this must be simple?

    Thanks for reading.

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: SOLVED! how to get Latest News on custom page and homepage Link to this post

    Try putting the method on Page.php, presuming both Homepage and HomePageNoIntro extend Page.

  • w1l
    Avatar
    Community Member
    13 Posts

    Re: SOLVED! how to get Latest News on custom page and homepage Link to this post

    Many thanks bartvanirsel - both HomePage and HomePageNoIntro do extend Page -good thinking.

    Unfortunately the result is exactly the same as previous ... items appear in the HomePage but not in HomePageNoIntro.

    Errk.

    Hmm i wonder might this problem be that the url path is different for these two pages.

    HomePage = /
    HomePageNoIntro = /home-alt

    ??

    I don't know silverstripe code well enough, but i wonder if something in this line can't handle the change in path?

    return ($holder) ? ArticlePage::get()->filter('ParentID', $holder->ID)->sort('Date DESC')->limit($num) : false;

  • bartvanirsel
    Avatar
    Community Member
    94 Posts

    Re: SOLVED! how to get Latest News on custom page and homepage Link to this post

    Hi, the line looks ok.

    If the latestnews Method is in Page.php and both other page types exend it, this method should work.
    The path does not matter.

  • w1l
    Avatar
    Community Member
    13 Posts

    Re: SOLVED! how to get Latest News on custom page and homepage Link to this post

    SOLVED!

    The HomePageNoIntro.ss page was looping <% include NewsTeaser %> ... when it should have been <% include ArticleTeaser %>

    So the Controller was fine as you said bartvanirsel. Thanks very much for your advice ... was pulling hair on this one!

    /w

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