Fetch first image for content-cards

Hi. I’m using kirby for my blog. I’m having some problems trying to fetch the image to use it in my content-cards.

The following code is for article.php. Here everything is fine, I can see my image if I try to acces my article.

<?php snippet('headerarticol') ?>
<?php snippet('breadcrumb') ?>
<?php snippet('sidebar') ?>

<section class="containerarticol">
  <article class="articol">
    <?php if($image = $page->image()): ?>
    <img src="<?= $image->resize(900, 900)->url() ?>" alt="">
    <?php endif ?>
    <div class="rating">
    <?php snippet('thumb-rating'); ?>
    </div>
    <a href="http://www.facebook.com/sharer.php?u=<?= rawurlencode ($page->url()); ?>" target="_blank" title="Share on Facebook">
  Share on Facebook
    </a>
    <h1><?= $page->Headline()->html() ?></h1>
    <?= $page->text()->kirbytext() ?>
    <?= $page->tags()->html() ?>
    <?= $page->published()->html() ?>

  </article>

</section>

<?php if($author = $page->author()->toUser()): ?>
  <section class="autor">

    <h2>Autor: <?= $author->name() ?></h2>

    <?php if($avatar = $author->avatar()): ?>
      <figure>
        <img src="<?= $avatar->url() ?>">
      </figure>
    <?php endif ?>

    <?= $author->bio()->kirbytext() ?>

    <h2>On the web:</h2>

    <ul>
      <li><a href="<?= $author->website() ?>">Website</a></li>
      <li><a href="<?= $author->instagram() ?>">Twitter</a></li>
    </ul>

  </section>
<?php endif ?>

<?php snippet('footer') ?>
</div>

Now the following code is for my content-cards. I’ve tryed to fetch specific image, but didn’t worked. Anyway… what i really want is to fetch the first image from my article.

  <?php foreach($page->children()->listed()->flip()->paginate(8) as $article): ?>

  <article class="card">
    <?php if($image = $page->image()): ?>
    <img src="<?= $image->url() ?>" alt="">
    <?php endif ?>
    <h2><?= $article->title()->html() ?></h2>
    <p><?= $article->text()->excerpt(300) ?></p>
    <?= $article->intro()->kirbytext() ?>
    <a href="<?= $article->url() ?>">Read more…</a>
    <h2><?= $article->title()->categories() ?></h2>
  </article>

  <?php endforeach ?>

</main>

Any ideeas? maybe i missed something, thanks guys.

Should be $article->image().

1 Like