mtn Posted March 3, 2018 Share Posted March 3, 2018 (edited) Layout: Pages are created as children of Categories. On the Pages template there is a "Select Option" field to select the particular subheading under which the page is to be displayed. Objective: The Category page is to be an index of child pages listed under various subheadings (as created by the Select Option field). Question: What is the syntax to reference that select option field of the child page template in order to display those subheadings and their respective child pages? Presently, I have a $subcats variable containing the name of the appropriate select option field for the Category and the following code which simply displays the sorted child pages (sans subheadings): $entries = $page->children("sort=$subcats, sort=page_headline"); foreach($entries as $entry) { echo "<div class='listing'>"; echo "<img src='{$entry->page_main_image->url}' alt='{$entry->page_main_image->description}'>"; echo "<h2>$entry->page_headline</h2>"; echo "<p>$entry->page_summary <a href='$entry->url'>Read on</a></p>"; echo "</div>"; } Edited March 3, 2018 by kongondo code blocks Link to comment Share on other sites More sharing options...
kongondo Posted March 3, 2018 Share Posted March 3, 2018 I am not sure I follow. A page, whether a child or not, has access to all the fields contained in the template that that page uses. So, if $entry is a child page, $entry can reference any field in the template it uses. If the selection option field is called categories, $entry->categories references the option field. If it is a single select option field, then you can just echo that out. If it is a multiple selection option field, you need to loop through it, i.e. foreach($entry->categories as $cat). I'm probably missing the obvious here, being late Saturday and all that . Link to comment Share on other sites More sharing options...
Robin S Posted March 3, 2018 Share Posted March 3, 2018 This post outlines two strategies for grouping pages under headings according to category: Link to comment Share on other sites More sharing options...
mtn Posted March 5, 2018 Author Share Posted March 5, 2018 Thank you kongondo & Robin S! Use of your suggestions led to the following successful code (in case it may be helpful to others): $entries = $page->children("sort=$subcats, sort=page_headline"); $subtitle = ''; foreach($entries as $entry) { if($entry->$subcats->title !== $subtitle) { $subtitle = $entry->$subcats->title; echo "<h3>$subtitle</h3>" } echo "<div class='listing'>"; echo "<img src='{$entry->page_main_image->url}' alt='{$entry->page_main_image->description}'>"; echo "<h2>$entry->page_headline</h2>"; echo "<p>$entry->page_summary <a href='$entry->url'>Read on</a></p>"; echo "</div>"; } 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now