Makes sense - have added them as bugs on the github page @ https://github.com/nyeholt/silverstripe-news/issues
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.
- Previous 10 entries
- 1
- Page 22(current)
- 3
- Next 10 entries
Hey Marcus , trying out your news module (very nice work btw) . The main reason i am using the module is i need to automatically archive / file news articles by their published date. I am trying to create a latest news function that would pull the latest 5 published news articles and display them on the home page. I modified the function from the ss tutorial 2 but it doesn't seem to be pulling any records . Could you give me any pointers on how to achieve this? The code for the function is below
function LatestNews($num=5) {
$news = SiteTree::get_by_link('news');
return ($news ) ? DataObject::get("NewsArticle", "ParentID = $news ->ID", "OriginalPublishedDate DESC", "", $num) : false;
}
Thanks
Mindfusion, This is the code I used to get the 2 most recent on the home page...so it shouldn't be hard at all to get 5 like you need:
function LatestNews($num=2) {
$news = DataObject::get("NewsArticle","","OriginalPublishedDate DESC","",$num);
return $news;
}
and yes, I am using this same module so it should be a simple copy/paste for you, then change the $num=2 to $num=5.
Hi Terry , It worked ! Thanks a lot
Hi,
Congrats for the module, works fine and just what I needed. One suggestion though:
While on a NewsArticle page, I'd like to have a list with other articles in a sidebar.
If I'm not the only one here, isn't it useful to add a method to the NewsArticle class that pulls out other articles with the method you described above?
Now, I'm subclassing the NewsArticle class just for this method:
class MyCustom_NewsArticle extends NewsArticle {
public static $icon = 'news/images/newspaper';
public static $db = array();
public static $has_one = array();
public function Articles() {
$holder = new NewsHolder();
return $holder->Articles();
}
}
class MyCustom_NewsArticle_Controller extends Page_Controller {
}
But that kinda pollutes my Pagelist (to choose from) with another Page type, and NewsArticle alone just looks fine (And easier to explain to future users of my client).
Well, maybe there's another way, I just started with SilverStripe ;)
Ronald
Hi,
I tried the module and it is really great. But I want to show the news on homepage. I see the code you use but I don't know where to paste these codes. If you can help me, I will be very glad. Thanks...
If you are referencing my code, you can place it in your custom HomePage.php (I always put it in the Controller). Or you can put that code in the Page.php so you can actually access the news from anywhere in your site since most of your custom pages (if you have custom pages) will extend Page.php.
Does this work with ss3? i copied the code in the customehomepage.php but still cant see the latest news on the page :( any help pls..
- Previous 10 entries
- 1
- Page 22(current)
- 3
- Next 10 entries