Jump to:

1851 Posts in 1605 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Latest Blog items from specified Blog holder on home page?

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 2693 Views
  • qlex
    Avatar
    Community Member
    68 Posts

    Latest Blog items from specified Blog holder on home page? Link to this post

    Hi,
    i've been scratching my head over this for some time now.
    I have 3 different Blog Holders (each with different suffix specified in "metatags" tab in CMS).
    I want to display 3 blog entries (with limited number of characters) on my main page in sidebar.

    Inside of template's sidebar div, im inserting this code, which doesn't display anything:

    <% if ChildrenOf(blog) %>
    <% control ChildrenOf(blog) %>
    <% if Last(blog) %>
    <h3>$Title</h3>
    $Content.LimitWordCount(30) <br/><a href="$Link">Czytaj więcej...</a></p>
    <% end_if %>
    <% end_control %>
    <% end_if %>

    blog - is the suffix of my URL (as in metatags)
    I tried to rename it to Blog (as is my Page name) but with no luck either.

    Please help.

  • house98
    Avatar
    Community Member
    31 Posts

    Re: Latest Blog items from specified Blog holder on home page? Link to this post

    I don't know if any of this will help -- or maybe point you in the right direction.... But this is what I have for a health-related blog...

    <% if URLSegment == health %>
    <% control ChildrenOf(health-blog) %>
    <% if Last %>
    <h2>$Title</h2>
    $ParsedContent.TwoParagraphs
    <a href=$Link> Continue Reading $Title </a>
    <% end_if %>
    <% end_control %>
    <% end_if %>

    The TwoParagraphs item above was a custom created peice to show the first two paragraphs ... however I think there's a built-in function called $ParagraphSummary and/or $Content.FirstParagraph and/or $Content.LimitWordCount(50)

    Anywho -- hope it helps

  • house98
    Avatar
    Community Member
    31 Posts

    Re: Latest Blog items from specified Blog holder on home page? Link to this post

    btw, if anyone's interested the two-paragraph hack is as follows:

    file: sapphire/core/model/fieldtypes/Text.php

    Add the following function:

    /**
    * Cuation: Not XML/HTML-safe - does not respect closing tags.
    */
    function TwoParagraphs() {
    if(strpos( $this->value, "</p>" ) === false && strpos( $this->value, "</p>", strpos( $this->value, "</p>" ) + 4 ) === false) return $this->value;
    $data = substr( $this->value, 0, strpos( $this->value, "</p>", strpos( $this->value, "</p>" ) + 4 ) + 4 );
    if(strlen($data) < 20 && strpos( $this->value, "</p>", strlen($data) )) $data = substr( $this->value, 0, strpos( $this->value, "</p>", strlen($data) ) + 4 );
    return $data;
    }

    I just added this one after the function FirstParagraph

  • qlex
    Avatar
    Community Member
    68 Posts

    Re: Latest Blog items from specified Blog holder on home page? Link to this post

    HI, i have solved the issue by putting the following:
    Page.php

    function LatestNews($number=3) {   
          $holder = DataObject::get_one('BlogHolder', "Title = 'AktualnoÅ›ci'");
          return DataObject::get('BlogEntry', "ParentID = {$holder->ID}","Created DESC", false, $number);
       }


    where Aktualności is the Page Name of my BlogHolder

    Page.ss

    <% control LatestNews %>
    <h3>$Title</h3>
    <p>$Content.LimitWordCount(30) <br/><a href="$Link">Read more...</a></p>
    <% end_control %>

    Thanx to _dab_ on irc for helping me out!

    2693 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.