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.

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   2051 Views


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:


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

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

Thanks in advance.



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


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.


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.


Community Member, 253 Posts

18 August 2009 at 2:30am


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:

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