We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Discussion, Runway

Output from multiple collections using different templates

Hey,

Following on from my previous thread: http://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'
]);
Marc Sanders

Marc Sanders 0 points

  • 1 year ago

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?

Duncan Revell

Duncan Revell 78 points
Registered Developer

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.

Drew McLellan

Drew McLellan 2637 points
Perch Support

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?

Drew McLellan

Drew McLellan 2637 points
Perch Support

_date is the collection item's creation date.