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.

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   3287 Views


Community Member, 68 Posts

1 June 2009 at 11:16pm

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) %>
      $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.


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


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



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:

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

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

Thanx to _dab_ on irc for helping me out!