Jon Posted December 26, 2015 Share Posted December 26, 2015 Hello I am looking for abit advice on how to achieve this. I have a number of pages all containing a date. I would like to display the results sorted by dates but with a header for each month so for example. April Date 1 Date 2 Date 3 May Date 1 Date 2 Etc Does process wire have any built in function in the API for this? Or will it need to be done via a database query Cheers Jon Link to comment Share on other sites More sharing options...
Macrura Posted December 27, 2015 Share Posted December 27, 2015 yes, there is an extensive discussion of that here, with code of how to achieve that: https://processwire.com/talk/topic/4991-sub-arrays-dates-times-and-pure-hell/ other options: https://processwire.com/talk/topic/6733-better-way-to-finding-all-years/#entry65975 https://processwire.com/talk/topic/11690-display-results-with-a-year-heading-using-datetime-field/?p=108709 1 Link to comment Share on other sites More sharing options...
rick Posted December 27, 2015 Share Posted December 27, 2015 Macrura, that second link under 'others' says I don't have permission to view this forum. Link to comment Share on other sites More sharing options...
Macrura Posted December 27, 2015 Share Posted December 27, 2015 sorry, yeah that was a profields; removed it now...not super relevant anyway Link to comment Share on other sites More sharing options...
tpr Posted December 27, 2015 Share Posted December 27, 2015 How about sort pages by date (in the main query), and echo month name if it's different from the previous? 4 Link to comment Share on other sites More sharing options...
Jon Posted December 28, 2015 Author Share Posted December 28, 2015 Hello guys, Thanks for the info guys, Macrura that post was very useful and managed to adapt it to meet the my needs. With regards to the wire('page') find is that specifically for getting repeater fields? I like the way you can add properties aswell that's cool! Cheers once again guys Link to comment Share on other sites More sharing options...
Macrura Posted December 28, 2015 Share Posted December 28, 2015 @Jon - the wire class can be used inside functions - so in the case of Joss' issue, he wanted the solution to be in a function. when outside of a function like in a template you can use the $pages variable directly... 1 Link to comment Share on other sites More sharing options...
Robin S Posted April 23, 2016 Share Posted April 23, 2016 How about sort pages by date (in the main query), and echo month name if it's different from the previous? Just used this excellent suggestion and thought I might as well post some code here. $upcoming_events = $pages->find("template=event, event_date>=today, sort=event_date"); $prev_event_month = ""; foreach($upcoming_events as $upcoming_event) { $month = date("F", $upcoming_event->getUnformatted("event_date")); if($month !== $prev_event_month) { echo "<h2>{$month}</h2>"; } echo "<h3>{$upcoming_event->title}</h3>"; // more event markup here $prev_event_month = $month; } 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