Main page distinction

I use code from docs to make logo linkable to the main page only when it’s not already open:

<h1>
  <?php if($page->isHomePage()): ?>
    <img src="../somewhere" ?>" />
  <?php else: ?>
    <a href="<?php echo url() ?>">
    <img src="../somewhere" ?>" />
    </a>
  <?php endif ?>
</h1>   

And this works at the search page, which uses different template and is located at http://site.com/search, while other pages, which use main blog template and look like http://site.com/tag:smth are operating as if they are main, i.e. logo is unclicable. Changing code to use $page->isSite() doesn’t help

The reason is that although the URL uses a parameter, it is still the homepage, so the condition is true for all these URLs. You could add a condition that tests if the URL contains a tag.

<?php if($page->isHomePage() && ! param('tag'): ?>

(not tested)

Why do you want to make remove the link from the homepage?

Parse error: syntax error, unexpected '&&' (T_BOOLEAN_AND) in /opt/lampp/htdocs/test/site/templates/blog.php on line 4

it may sound like overperfectionizm, but i think it’s against usability - to link somewhere, where user is already.
all my links with class .active are {pointer-events: none;}

A missing parenthesis, mea culpa :blush:

<?php if($page->isHomePage() && ! param('tag')): ?>

Thank you very much once more. And what would be the proper way to include one more condition for links like http://site.com/year:2016/month:April ?

You could use the params() helper and check if the array it returns is empty:

<?php
$params = params();
if($page->isHomePage() && empty($params)): ?>

https://getkirby.com/docs/toolkit/api/helpers/params

I’ve made it to work only with <?php if($page->isHomePage() && ! param('tag') && ! param('year')): ?>
(dog-style coding :joy:) other variants don’t filter it properly. Satisfied anyway.

Well, as long as it works :slight_smile:

BTW: When posting blocks of code, could you pls. wrap them in three backticks before and after the code block on a separate line? Makes it much more readable, thanks a lot!

1 Like