我正在SilverStripe網站上工作並安裝了blog module。根據SilverStripe上的類別篩選的循環博客帖子
我有我的博客設置了多個類別,如新聞,活動,公告,照片畫廊等
我遇到的問題是,我想向人們展示了我的首頁上每個類別的最新博客文章(標題,圖片,部分內容)。
我可以很容易循環使用此解決方案的博客文章:http://www.silverstripe.org/community/forums/blog-module-forum/show/102585?start=8
/mysite/code/Page.php
class Page_Controller extends ContentController {
public function latestBlog($num = 3) {
return BlogPost::get()
->sort('PublishDate', 'desc')
->limit($num);
}
}
/themes/simple/templates/Page.ss
<ol>
<% loop $latestBlog %>
<li>$Title</li>
<p>$Content</p>
<% end_loop %>
</ol>
但我不知道如何循環,而過濾由一隻貓egory。例如像這樣的邏輯:
return BlogPost::get()
->FILTER('Category', 'News')
->sort('PublishDate', 'desc')
->limit($num);
的想法是循環新聞和代碼它以一定的方式,所以它看起來頭版,然後循環照片畫廊不同。
我無法找到任何有關如何做到這一點的作品。
這可能嗎?
這樣做。非常感謝 –