1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » Latest Blog items from specified Blog holder on home page?
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 2399 Views |
-
Latest Blog items from specified Blog holder on home page?

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

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

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

2 June 2009 at 12:27am Last edited: 2 June 2009 8:52pm
HI, i have solved the issue by putting the following:
Page.phpfunction 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 BlogHolderPage.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!
| 2399 Views | ||
|
Page:
1
|
Go to Top |


