21307 Posts in 5737 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 673 Views |
-
List blog posts of a specific tag on home page

2 September 2011 at 2:59pm
I have a blog module installed and I'm trying to build a small components that specifically lists blog post of a specific tag, let's call it the "home" tag. How can I accomplish this? I looked at the PHP files for the BlogPage and BlogHolder but couldn't really find syntax to "query" for these blog posts.
Thanks
-
Re: List blog posts of a specific tag on home page

3 September 2011 at 7:34pm
In your Page.php:
public function getBlogsByTag($tag) {
return DataObject::get("BlogEntry", "Tag = '{$tag}'");
}In your HomePage.ss or Page.ss:
<% control getBlogsByTag(your-tag-name) %>
html code here...
<% end_control %> -
Re: List blog posts of a specific tag on home page

5 September 2011 at 7:04am Last edited: 5 September 2011 7:05am
Thanks Ryan. I tweaked it to use a LIKE in the SQL:
public function getBlogsByTag($tag) {
return DataObject::get("BlogEntry", "Tags LIKE '%{$tag}%'");
}How would I go about changing this to get me only the most recent single post by a tag and how would I access that in the template?
-
Re: List blog posts of a specific tag on home page

5 September 2011 at 10:45am
Hello, maybe you could try something like this in your function :
return DataObject::get("BlogEntry", "Tags LIKE '%{$tag}%'", Created DESC, "", 1);
| 673 Views | ||
|
Page:
1
|
Go to Top |



