teh
December 22, 2020, 4:07pm
1
Hi!
Silly question: How do I query the first image of a subpage within a pages section. My query code only always queries the first uploaded image but not the first sorted image.
image:
cover: true
ratio: 1/1
query: page.images.template("projectimage").sortBy("sort").first
Thanks!
Do all files have a sorting number? If you upload new images, they don’t automatically get a sorting number.
teh
December 22, 2020, 4:38pm
3
No they don’t have a sorting number, I sorted them in the panel after uploading.
Then they should have a sorting number in their meta data file.
1 Like
teh
December 22, 2020, 4:41pm
5
Yeah, they do have that number!
And the template as well?
mozi_h
December 22, 2020, 4:46pm
7
I had similar problems in my php template. I fixed it by supplying the first()
method with the referenced whole collection.
When filtering, the first()
(and similar) methods seem to use the unfiltered list as a reference; manually providing the correct, filtered one fixes this.
This may or may not work in blueprints. I can’t confirm this as I’m on mobile atm.
@mozi_h I can’t reproduce that behavior in a template. First()
doesn’t accept any parameters, anyway.
teh
December 22, 2020, 4:57pm
9
The chain works in a php template but not as a blueprint query
1 Like
teh
December 22, 2020, 5:02pm
10
I have a feeling there’s a really simple solution to this one, since it’s a very basic feature to show the first image in a sorted collection.
Hm, I’m testing this in a 3.5 Starterkit and the image that is shown changes whenever I change the sorting order of the images in the section.
Although I haven’t tested with multiple file blueprints in a page yet.
mozi_h
December 22, 2020, 5:14pm
12
Perhaps query every image and limit it using max
?
Now tested with multiple sections and two templates, still works as expected.
@teh maybe try in a Starterkit.
1 Like
teh
December 22, 2020, 5:16pm
14
I’m testing it on 3.5 as well
The structure is: Site –> Projects –> Project
teh
December 22, 2020, 5:17pm
15
And the query is in the Projects blueprint. Maybe it’s in the wrong blueprint
You mean in a pages section for the project subpages in the projects blueprint, right?
Which is the same structure as photography > album in a Starterkit.
teh
December 22, 2020, 5:19pm
17
That’s the blueprint of the Projects’ page
columns:
- width: 1/2
sections:
published:
type: pages
status: listed
template: project
image:
cover: true
ratio: 1/1
query: page.images.template("projectimage").sortBy("sort").first
teh
December 22, 2020, 5:20pm
18
Yeah exactly, haven’t installed the starterkit, it’s plain though
teh
December 22, 2020, 5:25pm
20
Thanks for trying though! Have a nice Christmas time