I’m trying to show on my home-page some specific images (rather that just one image as a cover). In my blueprint, I chance the cover entries, as a multiple, however, when I run the code in my homepage, it’s still show only one image instead of multiples ones.
Anyone have any leads how I can target some specific images in my album and show it randomly in my homepage?
Your question is a little contradictory, and you dont say which version of Kirby you are using? There are several ways to do what I think you are asking, but I need to know the Kirby version to answer correctly. With Kirby 3 you can use a files section and a files field to upload the images and set the them into a gallery field. Then in your template you use shuffle() and limit() to load a random one from a specific list of images.
With kirby 2, it is probably easiest to use the images plugin, in combination with shuffle() and limit(). Alternatively you can name the files with a prefix and use filterby to find them and show just one, again using shuffle and limit.
hi thank you for taking the time of answer.
I’m using Kirby 3.
I know how to display images in the gallery, and how to shuffle them, but I’ll try to explain in more details what I’m trying to achieve.
with kirby 3, in your home page, you are to display a cover picture of your album. what i would like to do is display multiple (but selected) cover of this album in the home page randomly. I tried to chance the blueprint, but when i run the code only one images will be display.
Changing the blueprint wont help much, since its the PHP templates and snippets that dictate how things show up on the site. The blue prints just dictate how things are stored.
Welcome to the forum by the way, i see you are a new user
Kirby tries not to dictate anything. The only required field is the title field, since it uses that to generate a URL for the page. Anything else is up to you. The Starterkit is a basic setup showing most of the main features to help people get up and running and understand how kirby works.
If you used the plainkit instead of the starter kit, you will see Kirby from scratch, meaning you have to setup everything how you like it.
But please, if you get stuck further, just ask
Btw, you could use query language to pull images from any page into a field, and use that to base random from. That way would mean that, yes, you can do it visually in the panel. You would not need the toggle field in the meta data then.
Assuming that you have already changed the cover field in /site/blueprints/pages/album.ymlto accept multiple images instead of only one, you can fetch those images like this:
foreach ($albums as $album) {
$images = $album->cover()->toFiles();
foreach ($images as $image) {
// do sth. with image
}
}
Note however that in the Starterkit, there is a cover() method defined in a page model (’/site/models/album.php) that you would have to remove to make the above code work.