Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Blog Module /

Discuss the Blog Module.

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

Latest Blog items from specified Blog holder on home page?


Go to End


4 Posts   3325 Views

Avatar
qlex

Community Member, 68 Posts

1 June 2009 at 11:16pm

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.

Avatar
house98

Community Member, 31 Posts

1 June 2009 at 11:40pm

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 :)

Avatar
house98

Community Member, 31 Posts

1 June 2009 at 11:44pm

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

:)

Avatar
qlex

Community Member, 68 Posts

2 June 2009 at 12:27am

Edited: 02/06/2009 8:52pm

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!