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.

Blog Module /

Discuss the Blog Module.

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

Latest articles from multiple Blogs on Homepage required


Go to End


5 Posts   2544 Views

Avatar
Beachwalker

Community Member, 4 Posts

16 August 2009 at 11:03am

Hi all
I'm trying to create a list of the latest blog articles from the many Blog Holders on my site. At present I only get the articles from one of the Blogs. Can anyone help please???

My code so far is:

...Homepage.php......................................................

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

...Homepage.ss.........................................................

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

Thanks in advance.

G

Avatar
Willr

Forum Moderator, 5523 Posts

16 August 2009 at 6:17pm

It is because you are getting 1 blog holder - $news = DataObject::get_one("BlogHolder"); then limiting the next get statement by that ID. Try

function LatestNews($num=5) { 
return DataObject::get("BlogEntry", "", "Date DESC", "", $num);
}

Avatar
Beachwalker

Community Member, 4 Posts

17 August 2009 at 6:51pm

Thanks, that worked a treat:-) But that also begs another question, is it possible to specify which Blogs the function queries? This is not an academic question, I could actually use this. It would be useful to be able to have "local" latest blog items lists. But for that I would need to be able to specify the blog to pull the latest 5 articles from.
Cheers

Avatar
lozhowlett

Community Member, 151 Posts

18 August 2009 at 1:16am

Stupid question but for the life of me I cant find homepage.php!! Where is it within the folder structure? Thanks.

Avatar
dhensby

Community Member, 253 Posts

18 August 2009 at 2:30am

@lozhowlett

You have to create it as a page type.

It would be located in /mysite/code/homepage.php (if you put it there).

See the tutorials for help: http://doc.silverstripe.com/doku.php?id=tutorial:1-building-a-basic-site#creating_a_new_page_type

@Beachwalker
Surely using a filter along the lines of (psuedo) ParentId in (id1,id2,id3,...) or if just one, using your original filter would work.

That should work, but I haven't tried it. Give it a go, have a play, and if you get something to work, post it back :D