Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

News on home page


Go to End


2 Posts   454 Views

Avatar
tomjohn

Community Member, 19 Posts

2 July 2014 at 6:18am

I have site with menu:

Home
Category1
---Subcategory
---Subcategory
---Subcategory
Category2
---Subcategory
---Subcategory
---Subcategory
Category3
---Subcategory
---Subcategory
---Subcategory
Category4
---Subcategory
---Subcategory
---Subcategory

Subcategories have news, but all news are visible only in parent category. Subcategories are hidden on page. I use in CategoryPage.php code :

$pageIDs = $this->getDescendantIDList();
$doSet = DataObject::get(
$callerClass = "News",
$filter = "`CategoryPageID` IN (" . implode(",", $pageIDs) . ")" . $filterStatement,
$sort = "Created DESC",
//$sort = "RAND()",
$join = ""

);

It list all news from subcategories on category page.

Now I want put on home page 4 modules with a few news from each category. How can I change this code to work?

Code:
$doSet = DataObject::get(
$callerClass = "News",
$filter = "`CategoryPageID` = '7'" . $filterStatement,

$sort = "ID DESC",
$join = ""
);
give me news from only one subcategory.
sSomeone can help me?

Avatar
Willr

Forum Moderator, 5523 Posts

3 July 2014 at 9:55pm

give me news from only one subcategory.

If news are a child page of the subcategory then an additional filter like ParentID = '4' will get you just news under '4'