Forum
Output from multiple collections using different templates
Hey,
Following on from my previous thread: https://forum.grabaperch.com/forum/08-25-2017-suggestions-multiple-collections-or-single-collection-approach
I have ran into a little roadblock that I can't seem to figure out.
I have two collections setup, one named articles and one named testimonials. The articles collection uses an article based template with the standard fields you would expect, title, image, body, summary, date. The testimonials collection uses a template with fields including testimonial and name.
I can't seem to figure out how to output the items in date order using the two different templates.
Using the following function, I did manage to output both collections when they both used the same template.
perch_collection(['Articles','Stories'], [
'template' => 'list.html',
'sort' => 'date',
'sort-order' => 'DESC'
]);
For reference, this is what I am trying to create:
https://www.dropbox.com/s/00bk3t23fx6ym8z/Screen%20Shot%202018-01-16%20at%2022.34.57.png
I'm not sure if it would be easier using the blog app and two different post types?
Both collections need to have a date field with the same name (I guess
date
- so you can sort by this field).Then create a template that includes the fields you want to see from both collections. This template might need a fair few
if exists
tags to keep things tidy, but it should work.If not, you can use
_date
.I will looking at putting the template and solution together a little later. Will feedback once complete.
Thanks for the suggestions so far both.
Got it all working, thank you both for your help. I will post a link to the site once complete.
Just out of interest Drew, what is the _date field. How is it populated, is it updated each time the region is edited or populated with the date the region was created?
_date
is the collection item's creation date.