Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Blog entries on main homepage.

Discuss the Blog Module.

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

Page: 1 2 3
Go to End
Author Topic: 6199 Views
  • Boundbystars
    Avatar
    Community Member
    4 Posts

    Blog entries on main homepage. Link to this post

    Hey guys I looked around for awhile for an answer to this... And I have been beating my brain up over it.

    I have a "homepage" page type that I would like to display the 5 latest blog post snippets on kinda like a "news" section.
    I have tried various things and nothing has worked.

    I am so LOST...

    Help me out and I'll buy your a soda!

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Blog entries on main homepage. Link to this post

    Hi... welcome to Silverstripe...

          $BlogEntries = DataObject::get_one("BlogHolder");
          return DataObject::get("BlogEntry", "ParentID = $BlogEntries->ID", "Date DESC", "", 5);

    Can we make that soda a beer ?

  • Gutur
    Avatar
    Community Member
    17 Posts

    Re: Blog entries on main homepage. Link to this post

    Same requirement with one of my clients ;)
    Tried this and that. Got it to just _be_ the homepage and show the latest entries. But adding entries via the frontend doesn't work and the link to the archives is pointing to "nonexistant" page. Kinda lost here since im quite new to SiStri.
    Going to reinstall / update but any help, experience, tricks would be very appreciated!
    /Carsten

    <edit>Fuzz10, you just posted while I was writing >_<
    Thanks for the snippet but I still lack some of the basic functionality (see above). Well I'm going to reinstall / upgrade and then see. Maybe a new post then would be appropriate ;)
    /Gutur
    </edit>

  • Chengaria
    Avatar
    Community Member
    3 Posts

    Re: Blog entries on main homepage. Link to this post

    @Fuzz10 (or anyone else reading this that may shed some light)

    I am new to SilverStripe and I'm looking for some additional help on this topic. Do you mind expanding a bit on your snippet on how to actually go about using it? Or if you can point me in the right direction of where I can find more detail, tutorial, documentation, etc. on implementing items in this fashion.

    Thanks in advance!

  • Gutur
    Avatar
    Community Member
    17 Posts

    Re: Blog entries on main homepage. Link to this post

    Well Chen, that's very straight forward:
    You have to put code like that in either existing or new page templates. I suggest you take the time and do the tutorials, they are really worth it!
    http://doc.silverstripe.com/doku.php?id=tutorials

  • MrHyde
    Avatar
    Community Member
    23 Posts

    Re: Blog entries on main homepage. Link to this post

    Well, I had the same problem a while ago:

    Homepage.php in mysite/code/
    $num is the number of news shown on your homepage

    class HomePage_Controller extends Page_Controller {

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

    }

    and in Homepage.ss in templates/layout/

    <% control LatestNews %>
    <h5>$MenuTitle</h5>
    <p>$Content.LimitWordCount(30) <br ><a href="$Link">Read the full post …</a></p>
    <% end_control %>

  • Chengaria
    Avatar
    Community Member
    3 Posts

    Re: Blog entries on main homepage. Link to this post

    Thanks for the info.. I am slowly going through the tutorials, in my scanning through them initially I couldn't find anything specifically illustrating this..

    @MrHyde
    Thank you very much for sharing your code snippets, you have shown me the light! =)

  • George
    Avatar
    Community Member
    41 Posts

    Re: Blog entries on main homepage. Link to this post

    how is a blog definable when more blogs are active?
    I have tried $news = DataObject::get_one("BlogHolder"); and as BlogHolder the name of the blog, but nothing is shown.

    Some hints?

    6199 Views
Page: 1 2 3
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.