Show Posts Only in One Language

I have a site in three languages, but the blog posts are only in one language. I put the code below in the home template and logically, the blog entries show up in the other language pages too. Since there is only one home template, how can I filter the code so that the latest posts show up only in the German page?

<section class="bg-light" >
<div class="container" >
<h2 class="font-weight-normal pb-6 pl-3 ls-1c">Neue Blogeinträge</h2>
<div class="card-columns  ">	
<?php foreach ($kirby->collection('articles')->limit(3) as $article) : ?>
	<div class=" card bg-white shadow  m-3" >
	  <?php if($img = $article->cover()->toFile()): ?>
  <a href="<?= $article->url() ?>">
          <img class="img-fluid" src="<?= $img->url() ?>" alt="<?= $img->alt() ?>" >
<?php endif ?>	
        <div class="card-body p-x-3 pt-3 pb-1">
    <h3 class="font-weight-normal ls-1c pb-3" ><a href="<?= $article->url() ?>" class=" text-800"><?= $article->title()->html() ?></a></h3>
    <?= $article->desc()->kt()->excerpt(120) ?>
    <p class="font-weight-normal pt-3"><a href="<?= $article->url() ?>"><?= $site->labelReadMore()->html() ?></a></p>
<?php endforeach ?></div>

Thanks in advance for any help.

PS: I’m rather excited, because I’m almost finished with my site.



Perhaps I can create snippets for the body of the home template for each language, but then how can I tell Kirby to go to e.g. snippets/homebodyDe, snippets/homebodyTr or snippets/homebodyEn ?

Wrap the blog listing in an if clause:

<?php if($kirby->languageCode() === 'de') : ?>
<?php endif; ?>

Thanks a lot! That works fine.



1 Like