21309 Posts in 5738 Topics by 2603 members
| Go to End | Next > | |
| Author | Topic: | 2010 Views |
-
News from multiple holders within a section

21 February 2009 at 2:47am
Hi,
I'm trying to create a rather complex news system. My website has a number of sections, some of which have more than one news holders and what I want is for the root of that section to have all of is child news (across all of the holders within that section).
I hope this makes sense.I have got an overall news, which shows everything and a individual news for that specific holder, but I've got stuck on this bit. If anyone has any clue, I'd greatly appreciate it.
Thanks.
-
Re: News from multiple holders within a section

21 February 2009 at 3:20am Last edited: 21 February 2009 3:23am
Bit of a hack but it should work. There is probably a cleaner way of doing it.....
function LatestNewsInSection(){
$Holders = DataObject::get('ArticleHolder', 'ParentID= $this->ID');
if($Holders){
$i = 0
foreach($Holders as $Holder){if($i == 0){
$Filter = 'ParentID =' . $Holder->ID;
$i=1;
}
else{
$Filter = $Filter . ' OR ParentID =' . $Holder->ID;
}}
return DataObject::get('ArticlePage', '$Filter');
}
else{
return flase;
}
} -
Re: News from multiple holders within a section

21 February 2009 at 4:43am
Thanks for the quick reply.
I seem to get issues with the first line: $Holders = DataObject::get('ArticleHolder', 'ParentID= $this->ID');
it only works if I have get_one, but then it's obviously only getting 1 holder.It looks like the code would do what I want if only I could get it to work
.
Thanks again. -
Re: News from multiple holders within a section

21 February 2009 at 5:13am
hmmm that is strange....what happens if you just have DataObject::get('ArticleHolder');
Perhaps the $this->ID needs curly braces: '{$this->ID}', or just separate it completely :
$ID = $this->ID;
DataObject::get('ArticleHolder', 'ParentID= $ID'); -
Re: News from multiple holders within a section

21 February 2009 at 6:06am
OK, I'm getting closer.
using: $Holders = DataObject::get('ArticleHolder'); returns me 3 ArticleHolder's (which is correct across the whole site).
But when I use: $Holders = DataObject::get('ArticleHolder', 'ParentID =' . $this->ID); to get all the holders in the section, it only looks at the direct children.I need to somehow combine the two.
Thanks for all your help so far. -
Re: News from multiple holders within a section

21 February 2009 at 6:10am
So your article holders are not direct children of your section? Hmm that makes it harder because we don't have a field in the Article Holder to identify which section it is in......
Any chance you could show me what your site structure looks like by class? something like:
PageTypeA
---ArticleHolder
---PageTypeB
--------ArticleHolder
PageTypeC
---PageTypeD
--------ArticleHodleretc.
-
Re: News from multiple holders within a section

21 February 2009 at 6:33am
Ahh yes, I see now. The code would work if I had two article holders inside the section rather than at lower levels.
My current structure is as follows:PageLevel1-(a)
---ArticleHolder
---PageLevel2
PageLevel1-(b)
---PageLevel2
--------ArticleHolder
---PageLevel2
--------ArticleHolderSo on each PageLevel1 I'd like to show the content from the ArticleHolders in lower levels. On PageLevel1-(a) that easy because it's a direct child, but on PageLevel1-(b) I'd like to see the children from both ArticleHolders.
Hope that makes sense.
-
Re: News from multiple holders within a section

21 February 2009 at 6:37am
Ok, I think your best bet for this would be to have a section tag in the ArticleHolder which you can set, say a the URLSegment of the top level page. That way in you getLatestArticles Function you can do:
DataObject::get('ArticleHolder', 'Section = $this->URLSegment');
| 2010 Views | ||
| Go to Top | Next > |


