Hey there,
I am trying to show on my project detail page the thumb-image of the next project.
Can someone help me how to implement this?
Thanks in advance
Hey there,
I am trying to show on my project detail page the thumb-image of the next project.
Can someone help me how to implement this?
Thanks in advance
This should work:
<?php
if($page->hasNext()) {
$image = $page->next()->images()->first();
echo thumb($image, array('width' => 300));
}
?>
You can use the nextVisible() page method to get the next visible sibling.
If you need more help, it’s necessary to know some more details, like the structure of your project pages or which image should be displayed (if there are more than one).
Edit: @texnixe was a bit faster with her reply, but maybe this answer is also helpful
@flokosiol: definitely!
If you only want to consider visible pages, the code above would look like this:
<?php
if($page->hasNextVisible()) {
$image = $page->nextVisible()->images()->first();
echo thumb($image, array('width' => 300));
}
?>
Thanks for your answers.
For any reasons no image is shown up.
I am calling the thumbs on the homepage like this:
<?php echo snippet('thumb', array('project' => $project)) ?>
But on the project-detail page it is not working with the next project
Could you please post your complete code, not just the call to the snippet? You are probably use $page
where you should be using $project
, but I have no crystal ball at my disposal.
Like I said before. Calling the thumb on the homepage:
<?php echo snippet('thumb', array('project' => $project)) ?>
Here is how I am calling the other images on the project detail page:
<?php foreach($page->gallery()->yaml() as $image): ?>
<?php if($img = $page->image($image)): ?>
<div class="swiper-slide"> <img src="<?= $img->url() ?>" alt="<?= $page->title()->html() ?>" /></div>
<?php endif ?>
<?php endforeach ?>
For any reason your code is only working in my second project. Its not showing the thumb of the first project but the second image of the slideshow of this project
I must admit I’m quite confused . What has the snippet on the homepage got to do with your original question of showing a thumb of the next project on a particular projects detail page?
I thought it just help you… Sorry I am very very new to all of this
No problem . Could you please just post the code of your project detail page including the part where you try to fetch the image for the next project?
Sure:
<?php snippet('head') ?>
<?php snippet ("header") ?>
<div class="image-hover">
<?php
if($page->hasNextVisible()) {
$image = $page->nextVisible()->images()->first();
echo thumb($image, array('width' => 300));
}
?>
</div>
<main class="grid-1280">
<section class="row">
<article class="col b100">
<div class="swiper-pagination-number">01/10</div>
</article>
</section>
</main>
<div class="swiper-container">
<div class="swiper-wrapper">
<?php foreach($page->gallery()->yaml() as $image): ?>
<?php if($img = $page->image($image)): ?>
<div class="swiper-slide"> <img src="<?= $img->url() ?>" alt="<?= $page->title()->html() ?>" /></div>
<?php endif ?>
<?php endforeach ?>
</div>
<div class="button-prev"></div>
<div class="button-next"></div>
</div>
<main class="grid-1280">
<section class="row">
<article class="col b100">
<div id="anchor1" class="project-text text-l"><?php echo $page->description() ?></div>
<article class="col b25">
<div class="project-specs">
<?php if(!$page->team()->empty()): ?>
<p>With:<span><?php echo $page->team()->html()?></span></p>
<?php endif ?>
<?php if(!$page->page()->empty()): ?>
<p>Visit:<span><a href=<?php echo $page->page()->link() ?></a></span></p>
<?php endif ?>
</div>
</article>
<article class="col b60">
<div class="project-services">
<p>Services:</p>
<div class="services-tags">
<ul>
<?php foreach($page->tags()->split(',') as $tag): ?>
<li><a><?php echo $tag ?></a></li>
<?php endforeach ?>
</ul>
</div>
</div>
</article>
</article>
</section>
</main>
<div class ="project-footer">
<div class="project-title-sml align"><p><?php echo $page->title()->html()?></p></div>
<div class="project-info align"><a href="#anchor1" class="scroll"><span><?php echo file_get_contents("assets/images/info-icn.svg")?></span>Info</a></div>
<div class="project-next align">
<?php if($next = $page->nextVisible()): ?>
<a href="<?php echo $next->url() ?>">
<p>Next Project: <span><?php echo $next->title()?></span></p>
</a>
<?php else: ?>
<a href="<?php echo page('projects')->children()->first()->url() ?>">
<p>Next Project: <span><?php echo page('projects')->children()->first()->title()?></span></p>
</a>
<?php endif ?>
</div>
<div class="swiper-pagination"></div>
</div>
<?php snippet('footer') ?>
Are the project pages all visible?
yes, just checked it. Every page is visible
And all projects have at least one image?
Yes every project has an image. Its really strange that only on the second project the image is coming up. But not the thumb, only the second image of the gallery
That is weird. Because the code works fine in a Kirby Starterkit.
Anyway, I think we should modify the code a bit to take care of the possibility that there might not always be an image:
<?php
if($page->hasNextVisible()) {
if($image = $page->nextVisible()->images()->first()) {
echo thumb($image, array('width' => 300));
}
}
?>
This won’t help with the current issue, I guess, but still.
Try to echo something to debug this a bit more:
<?php
if($page->hasNextVisible()) {
echo "Yeah, there is a visible next sibling";
if($image = $page->nextVisible()->images()->first()) {
echo "Great, there is also an image in the next project";
echo thumb($image, array('width' => 300));
}
}
?>
“Great, there is also an image in the next project” is shown in the second project.
Nothing on the first
Could you please post a screenshot of the subfolders of the projects folder?
I just saw that both texts are shown up on the second project