Panel – first image from subpage

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.

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

Yeah, they do have that number!

And the template as well?

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.

The chain works in a php template but not as a blueprint query :man_shrugging:

1 Like

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.

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

I’m testing it on 3.5 as well :confused:

The structure is: Site –> Projects –> Project

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.

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

Yeah exactly, haven’t installed the starterkit, it’s plain though

Hm, weird.

Thanks for trying though! Have a nice Christmas time