1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » Post recent (TAGGED) blog posts 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: | 2334 Views |
-
Post recent (TAGGED) blog posts on home page

24 January 2011 at 12:28pm
Has anyone any idea how to feature latest blog posts (in summarised form) in the sidebar of a homepage using only blog posts with a specific tag ie. "news"?
-
Re: Post recent (TAGGED) blog posts on home page

26 January 2011 at 9:55pm
Have a look at tutorial 2 for a general idea for how to get a set of pages - http://doc.silverstripe.org/sapphire/en/tutorials/2-extending-a-basic-site#showing-the-latest-news-on-the-homepage.
For the blog module tags - the tags are stored in a txt field as a comma separated list so in your database query you can use the LIKE '%news%' to filter for just news.
function LatestNews($num=5) {
return DataObject::get("ArticlePage", "Tags LIKE '%news%' ", "Date DESC", "", $num);
} -
Re: Post recent (TAGGED) blog posts on home page

26 January 2011 at 10:21pm
Hi Willr,
Just looking at this now.
I currently have the latest news set up as per that tutorial. If I make the suggested change in the HomePage.php file, what would I need to change in the HomePage.ss file?
I'm new so please bear with me.
-
Re: Post recent (TAGGED) blog posts on home page

27 January 2011 at 4:31pm
You wouldn't need to change the template as all you're basically doing is filtering the database query (from the PHP) to reduce and entries you're including.
-
Re: Post recent (TAGGED) blog posts on home page

28 January 2011 at 10:49am
I must be doing something wrong.
In my php file I have:
function LatestNews($num=5) {
return DataObject::get("ArticlePage", "Tags LIKE '%news%' ", "Date DESC", "", $num);
}In my .ss file I have:
<ul id="NewsList">
<% control LatestNews %>
<li class="newsDateTitle"><a href="$Link" title="Read more on "{$Title}"">$Title</a></li>
<li class="newsDateTitle">$Date.Nice</li>
<li class="newsSummary typography">$Content.FirstParagraph<a href="$Link" title="Read more on "{$Title}""> More...</a></li>
<% end_control %>
</ul>But I'm getting an error and the page doesn't work at all.
Have I missed something here?
-
Re: Post recent (TAGGED) blog posts on home page

30 January 2011 at 5:10pm
But I'm getting an error and the page doesn't work at all.
Posting the message (or a screenshot of the error) is much more useful. If you are getting a generic "Website Error" page then put your site into devmode. This enables full error messages.
function LatestNews($num=5) {
return DataObject::get("ArticlePage", "Tags LIKE '%news%' ", "Date DESC", "", $num);
}
If you are using the Blog then the PageType is "BlogEntry" not "ArticlePage".
The error page will have more useful messages.
-
Re: Post recent (TAGGED) blog posts on home page

31 January 2011 at 12:13am
Thanks for pointing that out.
Solved.
Much appreciated.
-
Re: Post recent (TAGGED) blog posts on home page

28 July 2011 at 8:32am
Hi,
I have a question that is related to this functionality. Or I guess an extension of this functionality. Even though I haven't tried it, I believe I understand how to implement what has been described in this thread if I wanted blog posts on my home page.
I am actually looking to put a few recent posts in a sidebox that will only appear on Blog Entry pages. (I think I can figure this part out). But I want the recent posts to only be posts that have the same tag as the blog entry that you are currently viewing. This is where I am getting stuck.
I am guessing it would use the first tag listed for the current blog entry. But I don't know what code/syntax is needed to grab the first tag associated with the post.
Any suggestions would be great. Thanks!
| 2334 Views | ||
|
Page:
1
|
Go to Top |


