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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   561 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'