Show section only on first page AND only if no filter is active

I display a large number of images divided on several pages using pagination. Additionally, the images can be filtered using tags.

Now I want to display a section with a randomly selected background image above the list of images. But only on the first page and only if no filter is active.

I have managed that the section is only displayed on the first page:

 <?php if ($pagination->isFirstPage()) : ?>
    <?php $imageUrl = ($image = page('archive')->children()->images()->filterBy('orientation', 'landscape')->shuffle()->first()) ? $image->url() : ''; ?>
    <section class="cover" style="background-image: url(<?= $imageUrl ?>)">

      ...

    </section>
  <?php endif ?>

How can I now also integrate the second condition, i.e. show the section only when no filter is active?

what do you use for filtering? Parameters or query string.

For example, if you use a parameter called tag, you would get this parameter with

$tag = param('tag');

Now when such a filter is active, this would return a string with a value. If it is not present, this variable will be null. So you can check that.

Exactly, I use a parameter called “tag” to filter. Therefore it is surely exactly the right way to check if the variable is null.

Due to lack of PHP knowledge, I simply don’t know how to integrate this into the if ($pagination->isFirstPage()) loop I’m currently already using…

 <?php if ($pagination->isFirstPage() && is_null(param('tag'))) : ?>

Awesome, thank you!