Thanks for your help. I got the listbox working but i'm still having some issues with getting the pages to show the posts associated with the topic. Here's what I currently have.
Prerequisites:
class EducationPost extends DataObject {
private static $db = ['Title' => 'Varchar'];
private static $belongs_many_many = ['Topics' => 'Topic'];
}
class Topic extends DataObject {
private static $db = ['Title' => 'Varchar'];
private static $has_one = ['TopicAggregatorPage' => 'TopicAggregatorPage'];
private static $many_many = ['EducationPosts' => 'EducationPost'];
}
class TopicAggregatorPage extends EducationPage {
private static $db = ['Title' => 'Varchar'];
private static $has_one = ['Topic' => 'Topic'];
}
TopicAggregatorPage:
<div class="row row-eq-height">
<% if $Topic.EducationPosts %>
<% loop $Topic.EducationPosts.Sort("Created", DESC) %>
<% if $MultipleOf(3) %>
<div class="row row-eq-height">
<% end_if %>
<div class="col-xs-12 col-sm-6 well sub-detail-block">
<img src="$MainImage.Filename">
<h3>$Title</h3>
<div class="text">$Teaser</div>
<p>$Topic</p>
</div>
<% if $MultipleOf(2) %>
<% if not $Last %>
</div>
<% end_if %>
<% end_if %>
<% end_loop %>
<% else %>
<h4>No results to display.</h3>
<% end_if %>
Currently this only ever shows me "No results to display." despite the fact that I have several posts associated with the page I'm looking at.
Additionally, I have a pagetype EdAggregatorPage that is a parent to several TopicAggregatorPages in the site tree, and I am trying to display posts for those topics on the EdAggregatorPage. I wrote a custom function to get these and build an arraylist (so I can sort, limit, etc as we decide what exactly we want the page to have). That code is as follows:
public function getChildPosts() {
$array = Array();
foreach($Child as $topic){
foreach($topic->EducationPosts as $edPost){
array_push($array, $edPost);
}
}
$list = new ArrayList($array);
return $list;
}
This worked previously, but has stopped working since I made the updates to fix the listbox. Am I missing something in the names or am I doing something else wrong? I feel like I am close but just can't quite sort it out.