Jump to:

1855 Posts in 1609 Topics by 562 members

Blog Module

SilverStripe Forums » Blog Module » SOLVED: Adding summary of Post to SideBar

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 402 Views
  • Riposte
    Community Member
    10 Posts

    SOLVED: Adding summary of Post to SideBar Link to this post

    Hi All
    I would like to add the last 3 blog post summaries (or first paragraphs?) to a sidebar.
    I tried this as a first step:

    <% if BlogEntries %>
          <% loop BlogEntries %>
             <% include BlogSummary %>
          <% end_loop %>
       <% else %>
          <h2><% _t('BlogHolder_ss.NOENTRIES', 'There are no blog entries') %></h2>
       <% end_if %>

    But it always returns 'There are no blog entires' which I guess indicates BlogEntries isn't populated when the home page loads.

    Any ideas where I am going wrong?

    SOLVED: This didn't come up in my forum search but reading the post "How to add blog tags to home page" below gave me the answer:

    Needed a retrieval function in my page.php file Page_Controller class:

    public function LatestBlogs($num=5) {
    return DataObject::get('BlogEntry', array('ShowInSearch'=>'1'), 'Date DESC', '', $num);

    Then in Page.ss

    <% if LatestBlogs %>
    <% loop LatestBlogs(2) %>
    <% end_loop %>

    Seems to work ok.


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.