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.

All other Modules /

Discuss all other Modules here.

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

News module or extension


Go to End


17 Posts   10290 Views

Avatar
Marcus

Administrator, 89 Posts

2 March 2011 at 4:22pm

Makes sense - have added them as bugs on the github page @ https://github.com/nyeholt/silverstripe-news/issues

Avatar
Mindfusion

Community Member, 7 Posts

24 August 2011 at 10:39am

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

Avatar
Terry Apodaca

Community Member, 112 Posts

24 August 2011 at 10:54am

Edited: 24/08/2011 10:54am

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.

Avatar
Mindfusion

Community Member, 7 Posts

24 August 2011 at 11:00am

Hi Terry , It worked ! Thanks a lot

Avatar
Ronaldo71

Community Member, 10 Posts

15 November 2011 at 3:23am

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

Avatar
erbaayunusemre

Community Member, 1 Post

28 December 2011 at 10:12am

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

Avatar
Terry Apodaca

Community Member, 112 Posts

28 December 2011 at 10:17am

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.

Avatar
Anas

Community Member, 4 Posts

17 August 2012 at 6:32pm

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