1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » Blog entries 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: | 2478 Views |
-
Blog entries on Home Page

13 April 2009 at 12:57am
I have been trying for the past few day to get the latest Blog entries displayed in the sidebar. I just can't seem to get it to work. I have followed the news tutorial. I am using the Black Candy theme and the latest version of silverstripe. I have created a homepage. Can anybody help me with the code I need to add to each page?
-
Re: Blog entries on Home Page

13 April 2009 at 10:09am
You need to add a function to your homepage controller to pull the data from the blog post, I use this:
function LatestPost($num=2) {
$blogpost = DataObject::get_one("BlogHolder");
return ($blogpost) ? DataObject::get("BlogEntry", "", "Date DESC", "", $num) : false;I am then able to use this in my homepage template:
<% control LatestPost %>
<ul>
<li><a href="$Link" title="Read more on "{$Title}"">$Title</a></li>
<li>$Date.Nice</li>
<li>$Content.FirstSentence</li>
</ul>
<% end_control %> -
Re: Blog entries on Home Page

15 April 2009 at 3:21pm
I'm so completely new to SS, please forgive me but when you refer to adding the function to the homepage controller, where in the tree would I find the file responsible for this.
-
Re: Blog entries on Home Page

15 April 2009 at 3:36pm
Oh righto, firstly I recommend you do the first couple of tutorials http://doc.silverstripe.com/doku.php?id=tutorials But specifically for this issue:
If you are just using a standard page for your homepage then you will need to add that function into the /mysite/code/Page.php file in the page controller, in a similar fashion to this http://pastie.org/446929
But if you have made a specific HomePage type of page then that will have its own controller in HomePage.php where the function should be placed
-
Re: Blog entries on Home Page

23 April 2009 at 8:24am
What if I also wanted to retrieve the number of comments on the blog post?
-
Re: Blog entries on Home Page

23 April 2009 at 8:43am
Okay I figured out how to get the number of comments, but maybe someone could explain to me how exactly this works.
I did so by adding $Comments.Count into the template file and it simply worked. What I'm confused about is, how are the comments magically made available to SS when my query ($latestPost = DataObject::get_one('BlogEntry', '', false, 'Created DESC')) is only selecting the blog entry. If I print_r($latestPost), I don't see anything about comments.
I guess when the template is rendered, $Comments tells SS to select the data from the related table?
| 2478 Views | ||
|
Page:
1
|
Go to Top |

