I’m building a section on my site called “live listings”. This section will allow me to upload “listings” via the cms. I input some basic information like title, text block, date etc.
On the HTML side of things, What I would like is to group these listings by date.
For example, I have added 3 listings as children of the live page via CMS. Each listing has a different date.
I would then like to have a small nav menu on the page itself which shows the dates of the listings I have added. Which ofcourse would filter by date.
So to make things clearer if I enter (1/12/2016) as a date for listing A. (2/12/2016) for listing B and (3/12/2016) for listing C. These dates are Thursday, Friday and Saturday. So on the page, I would like to show “Thurs, Fri, Sat” and once clicked these nav items would then only show the corresponding listings on that day.
So far I have the menu system outputting the days from the listings But I cannot figure out how to then group these listings by date and only show the specific ones.
Here is my code for the date nav menu.
I’m a bit confused. Do you want to group the items by day as it says in your topic header (so that under each day you list the corresponding items; but then the navigation would no make sense) or do you want to filter them like you would filter blog posts by tag like you explain later on in the text?
Yes the dates on the listings are converted to actual days (1/12/2016 -> Thurs).
All converted listing dates are then listed in the nav at the top of the page. (Ex: Thurs / Friday / Saturday ).
I have moved on and managed to get the listings to group by day.
<?php foreach($page->children()->groupBy('date') as $date => $items): ?>
<?php $day = strtotime($date); $today = date('D', $day); ?>
<ul class="<?php echo strtolower($today); ?>">
<?php foreach($items->sortBy('clicks', 'desc') as $item): ?>
<h1><?php echo $item->title(); ?></h1>
<?php echo $item->text()->kirbytext(); ?>
<?php endforeach ?>
<?php endforeach ?>
Apologises if im confusing you more, Im a little confused myself and trying to explain to the best of my abilitity
BTW. You should use
<li> elements inside