Sortable Featured Content

Hi guys,

I’m currently finishing a portfolio for a video production company. The content structure looks like this:

Directors
->Director
–>Videos ( featured checkbox)

For each video I have a checkbox to set the content “featured” and display it in a carousel.
Now my problem is that I can’t order the featured items because they don’t know about each other, and they are children of different parent pages (Directors).
Does anybody have an idea how I can make them sortable?

Cheers
Ben

You can’t sort them directly, but you could do this:

  • Add a new numeric “position” field to the video pages
  • Put numbers into that field on the different video pages. The larger the number, the later the page appears.
  • Use something like this in the template to print all featured videos sorted by their sorting number:
    <?php foreach(page('directors')->grandchildren()->filterBy('featured', true)->sortBy('position', 'asc') as $video): ?>
      ...
    <?php endforeach ?>
    

Thanks for that solution. It’s a shame you need to be on top of the indexes yourself and can’t do it with kirby.
I was hoping there is a way to display some kind of sortable list with all “featured” items.

I don’t think there is a solution for this out of the box. This is a very specific functionality you need there.
You could make a custom field for this.

What you could use is the following content structure:

Directors
 - Director
 - Director

Videos
 - Video (featured checkbox, director)
 - Video (featured checkbox, director)

Basically put all videos are in one directory and then link them to their respective directors with a select field:

fields:
  director:
    label: Director
    type: select
    options: query
    query:
      page: directors
      fetch: children
      value: '{{uid}}'
      text: '{{title}}'

You can then sort the videos directly.

Thanks Lukas, I’ll try this out!