OpenBayou Posted January 20, 2017 Posted January 20, 2017 I have a page called deals that has three sub-pages and those sub-pages have posts. Here's a short description of what my deals pages look like: Deals - Page A - - Sub-page 1 - - Sub-page 2 - - Sub-page 3 - Page B - - Sub-page 1 - Page C - - Sub-page 1 - - Sub-page 2 - - Sub-page 3 Right now it's sorted by sub-pages in page A, sub-pages in page B and sub-pages in page C. How do I sort sub-pages by publish date? This is what I've done so far and it doesn't do anything. <?php foreach($pages->get("/deals/")->children() as $post) { ?> <?php foreach($post->children("sort=-publish_date") as $child) { ?> <?php echo $child->deals_category?> <?php } } ?> Thanks for the help.
LostKobrakai Posted January 20, 2017 Posted January 20, 2017 <?php $subpages = $pages->find("has_parent=/deals/, template=subpage, sort=-publish_date"); foreach($subpages as $subpage): ?> <?php echo $subpage->deals_category?> <?php endforeach; ?> 2
Robin S Posted January 20, 2017 Posted January 20, 2017 Instead of... foreach($post->children("sort=-publish_date") as $child) { ...try... foreach($post->children()->sort("-publish_date") as $child) { I assume "publish_date" is a custom field you have added to your template - otherwise perhaps you are looking for "created". More likely "published". What's the deal with all the opening/closing PHP tags?
LostKobrakai Posted January 20, 2017 Posted January 20, 2017 9 minutes ago, Robin S said: What's the deal with all the opening/closing PHP tags? There's probably some html markup between those in the template.
OpenBayou Posted January 20, 2017 Author Posted January 20, 2017 1 hour ago, Robin S said: What's the deal with all the opening/closing PHP tags? Images, titles, description and adding <div>s Edit: this is the final product <?php foreach($pages->find("has_parent=/deals/, template=deals-post, sort=-created") as $child):?> <?php if(!$dealsTitle) : ?> <div class="top-id"> <div class="title"> <div class="title-id"> <?php echo $child->parent->parent->title;?> </div> <div class="togger-button-deals togger-button"> <img width="auto" height="20px" src="<?php echo $config->urls->templates?>imgs/arrow_down.svg"> </div> </div> <div style="display:none" class="description-deals description"> <?php echo $child->parent->parent->item_description;?> </div> <?php $dealsTitle = true;?> </div> <?php endif; ?> <div class="deals-item"> <div class="deals-store-left"> <img src="<?php echo $child->parent->post_image->first()->size(40,0)->url;?>"> </div> <div class="deals-right"> <div class="category"> <div class="title"> <?php echo $child->deals_category?> </div> </div> <div class="deals-title"> <?php echo $child->parent->title;?>: <?php echo $child->title;?> </div> <?php if($child->publish_until):?> <div class="deals-expire"> <div class="title"> expires: <?php echo date("M. d, Y",$child->getUnformatted("publish_until")); ?> </div> </div> <?php endif;?> </div> </div> <?php endforeach; ?>
OpenBayou Posted January 20, 2017 Author Posted January 20, 2017 Got it working! Thanks for the help. // show each page from deals and using the template 'deals-post' that's sorted by date created. <?php foreach($pages->find("has_parent=/deals/, template=deals-post, sort=-created") as $child):?> <?php echo $child->title?> <?php endforeach; ?>
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