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

BlogTree entries on homepage?


Go to End


2 Posts   1160 Views

Avatar
sajok

Community Member, 82 Posts

14 October 2010 at 1:48am

Hello,

I have set four main menu items as Blogtree page type, and under each blog tree I have other blogholders. I'm looking for a way to show the latest entries on the homepage exactly the same as what you see on blogTree page.

I was trying something like the following but it returned only entries from first blogHolder:

    function LatestNews($id) {
    $news = DataObject::get_one('BlogTree', "ParentID = $id");
    return ($news) ? DataObject::get("BlogEntry", "ParentID = $news->ID", "Date DESC", "", 1) : false;
    }

I would appreciate any help.. thanks

Avatar
Willr

Forum Moderator, 5523 Posts

28 October 2010 at 7:12pm

If you are trying to use <% control LatestNews($id) %> it won't work as the template engine doesn't support passing variables into functions.

One way if you want all the blog entries on the homepage is simply to use

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

To return the latest blog entries from anywhere.