Jump to:

1835 Posts in 1139 Topics by 554 members

Blog Module

SilverStripe Forums » Blog Module » Blog Posts on HomePage in Columns... Stuck!

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 1531 Views
  • stew
    Avatar
    Community Member
    30 Posts

    Blog Posts on HomePage in Columns... Stuck! Link to this post

    Hi guys,

    I've spent the day playing with SilverStripe and have fallen in love with the CMS and will be using it for pretty much all the sites I work on in future.

    However I've hit a bit of a stumbling block with my first Silverstripe site, I am trying to get two blog posts shown on the homepage as in this image: http://img527.imageshack.us/img527/4167/43445519.jpg

    I've managed to get blog posts to the homepage using code courtesy of Fuzz10:

    HomePage.php:

    function MyBlogEntries($limit = 1) {
    $BlogEntries = DataObject::get_one("BlogHolder");
    return ($BlogEntries) ? DataObject::get("BlogEntry", "ParentID = $BlogEntries->ID", "Date DESC", "", $limit) : false;
    }

    and

    HomePage.ss:

    <% control MyBlogEntries %> { ... } <% end_control%>

    In WordPress I would simply use two separate "wp_loop" statements, one for the latest and one for the second newest posts. Is there a way of doing the same here? The CSS side of things is already done so I am just stumped with the SilverStripe template code.

    Thanks for your help guys, very much appreciated,

    Stewart

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Blog Posts on HomePage in Columns... Stuck! Link to this post

    Your almost there, just change the line in HomePage.php to:

    function MyBlogEntries($limit = 2) {


    Should do the trick

  • stew
    Avatar
    Community Member
    30 Posts

    Re: Blog Posts on HomePage in Columns... Stuck! Link to this post

    Thanks Howard, I meant to say thanks last week but it's been a mad house! lol. Many thanks.

  • animasola
    Avatar
    Community Member
    121 Posts

    Re: Blog Posts on HomePage in Columns... Stuck! Link to this post

    Hi stew,

    I'm trying to do a similar task but can't really work it out since I'm relatively new to coding in SilverStripe. Could you please elaborate more on this part?

    <% control MyBlogEntries %> { ... } <% end_control%>

    What should I place in { ... }

    to display things such as title, author and date?

    Many thanks!

  • stew
    Avatar
    Community Member
    30 Posts

    Re: Blog Posts on HomePage in Columns... Stuck! Link to this post

    Hey,

    Within the HomePage.ss template file I placed this code:

    <% control MyBlogEntries %>
    <div class="newscolumn left">
    <h3>$Title</h3>
    <p>$Content <br ><a href="$Link">Read the full post …</a></p>
    </div>
    <% end_control %>

    What happens using that code is that for however many blog posts I want displayed (set using MyBlogEntries($limit = 2) in HomePage.php) it will loop everything inside the control brackets.

    So from there the css is simply that the newscolumns are set width (450px in this case) and the left class simply does float:left (I've recycled this from other code, the newscolumn class is used in the single post view). The CSS and class side of things is very messy I'll be honest, it could be cleaned up to drop it to one class, the project was pushed for time and I haven't had the time to go back and do some house cleaning on the project yet.

    Let me know if you are still having problems,

    Stewart

  • one
    Avatar
    Community Member
    6 Posts

    Re: Blog Posts on HomePage in Columns... Stuck! Link to this post

    Hi guys,

    I want to manage the number of the letters of the sentence of displayed blog.
    How??

    Please tell me.

  • one
    Avatar
    Community Member
    6 Posts
    1531 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.