rolspace.net Posted August 20, 2016 Share Posted August 20, 2016 (edited) Hi everyone I'm kinda new here and have a little problem. I'm working on a website for a band and I want to show Future and Past Tourdates (Shows). Now I managed to get the Dates to show up correctly but wonder how I could do the split between Future and Past shows. Here's my code so far: <table> <tr> <th>Date</th> <th>Venue</th> <th>City</th> <th>Ticket</th> </tr> <?php foreach ($pages->get('/shows/')->children as $show) { ?> <tr> <td><?php echo $show->show_date; ?></td> <td><?php echo $show->title; ?></td> <td><?php echo $show->show_venue; ?></td> <td><a href="<?php echo $show->show_ticket_url; ?>" target="_blank">get tickets</a> </td> </tr> <?php } ?> </table> Any quick solutions to this? Thanks Edited August 20, 2016 by LostKobrakai added codeblock Link to comment Share on other sites More sharing options...
adrian Posted August 20, 2016 Share Posted August 20, 2016 Hi @rolisx and welcome to the forums. foreach ($pages->get('/shows/')->children("show_date<=".time().", sort=show_date') as $show) { and then another one where the show_date is greater than the current time() 3 Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 20, 2016 Share Posted August 20, 2016 <?php $shows = $pages->get('/shows/')->children; $currentTime = time(); $future = $shows->find("show_date>$currentTime"); $past = $shows->not("show_date>$currentTime"); 4 Link to comment Share on other sites More sharing options...
horst Posted August 20, 2016 Share Posted August 20, 2016 <?php $threshold = strtotime(date('d.m.Y 00:00:00')); // = today $selectorFuture = "parent=/shows/, show_date>={$threshold}, sort=show_date"; // or: sort=-show_date $selectorPast = "parent=/shows/, show_date<{$threshold}, sort=show_date"; // or: sort=-show_date foreach($pages->find($selectorFuture) as $show) { // echo table rows here ... } foreach($pages->find($selectorPast) as $show) { // echo table rows here ... } 3 Link to comment Share on other sites More sharing options...
rolspace.net Posted August 20, 2016 Author Share Posted August 20, 2016 Thanks guys! I went with Horst's solution. Have a great weekend! 1 Link to comment Share on other sites More sharing options...
horst Posted August 20, 2016 Share Posted August 20, 2016 My code example is a bit lengthy. I copied it from an event template with another usecase. There we have a start_date and optionaly an end_date too. Only all future events and or currently active events should be shown on the site, also those where the start_date is in the past, but the end_date is in the future: $threshold = strtotime(date('d.m.Y 00:00:00')); $selector1 = "template=ptlist-events, event_disabled=0, event_date_start>={$threshold}, sort=event_date_start"; $selector2 = "template=ptlist-events, event_disabled=0, event_date_end>={$threshold}"; $events = $pages->find($selector1); // find all events that start today or in the future $events->add($pages->find($selector2)); // find all events that end in the future, even if they started in the past, // and add to PageArray $events->sort('event_date_start'); foreach($events as $k => $v) { printEvent($v); } PageArray stores by ID, so there are no duplicate entries in the final PageArray. 1 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