Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

755 Posts in 191 Topics by 245 members

Blog Module

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

Discuss the Blog Module.

Page: 1
Go to End
Author Topic: Latest Blog items from specified Blog holder on home page? 988 Views
  • qlex
    avatar
    Community Member
    47 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
    28 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
    28 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
    47 posts

    Re: Latest Blog items from specified Blog holder on home page? [SOLVED] 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!

    988 Views
Page: 1
Go to Top

Currently Online: Erin, jseth, Euphemismus

Welcome to our latest member: behaviourneeds

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

Comments on this website? Please give feedback.