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.

General Questions /

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

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

News on home page


Reply


2 Posts   181 Views

Avatar
tomjohn

Community Member, 6 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, 5513 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'