Beginner PHP question: Show tags if parent is collection as well as article?

Hi,

I’m on Kirby 4 and using the ZOON theme.

By default, tags only show in the page-meta when the parent is a collection, however I would like tags to show if the parent is an article, also.

I found the following in site/snippets/page-meta.php.

<?php if ($section->template() == 'collection'): ?>
      <?php if ($tags != '') : ?>
        <li class="tag">
          <?php $tags = $tags->split();
          foreach ($tags as $tag) : ?>
            <a href="<?= url($page->parent()->url(), ['params' => ['tag' => $tag]]) ?>">#<?= html($tag); ?></a>
          <?php endforeach ?>
        </li>
      <?php endif ?>
    <?php endif ?>

Unfortunately, my understanding of PHP is so limited that though I understand the line I need to change is:

<?php if ($section->template() == 'collection'): ?>

I do not know what to do to add article to it, nor even how to phrase the search for that. I tried:

<?php if ($section->template() == 'collection', 'article'): ?>

But that seems to break and I’m assuming it’s because of the ==?

Anyway, my understanding is still too limited, hence my asking; thanks for any help in advance.

<?php if(in_array($section->template(), ['collection', 'article']): ?>

or



<?php if ($section->template() == 'collection' || $section->template() == 'article' ): ?>
1 Like

Thank you Sonja!