Jump to:

1840 Posts in 1598 Topics by 557 members

Blog Module

SilverStripe Forums » Blog Module » Latest articles from multiple Blogs on Homepage required

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 1529 Views
  • Beachwalker
    Avatar
    Community Member
    4 Posts

    Latest articles from multiple Blogs on Homepage required Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Latest articles from multiple Blogs on Homepage required Link to this post

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

  • Beachwalker
    Avatar
    Community Member
    4 Posts

    Re: Latest articles from multiple Blogs on Homepage required Link to this post

    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

  • lozhowlett
    Avatar
    Community Member
    146 Posts

    Re: Latest articles from multiple Blogs on Homepage required Link to this post

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

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Latest articles from multiple Blogs on Homepage required Link to this post

    @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

    1529 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.