Tag function only works when blog is set as homepage

Hi,

I ran into something strange. I used the baseblog template as a start and modified it a bit. Everything works like a charm but when I decided not to use the blog as the homepage… the tag functionality stopped working. Although in the URL it shows the www.homepage.com/tag:something, the template set as “home” is displayed but not the tag page. When I switch back (blog as home), everything works as expected. What am I missing here? Although the code itself works, I post it here, maybe someone can give me a hint what I will have to adjust. Thanks.

<?php if(param('tag')): // show tag results ?>
    <?php $tag = urldecode(param('tag')); ?>
    <?php $articles = $pages->find('publications')->children()->visible()->filterBy('tags', $tag, ',')->flip()->paginate(10); ?>
    <div class="hero">
      <h1>&ldquo;<?php echo $tag ?>&rdquo;</h1>
      <div class="subtitle">Here are the publications we have found under this tag:</div>
    </div>
    <section class="content">
      <div class="text"><?php foreach($articles as $article): ?>
        <article>
          <h3><a href="<?php echo $article->url() ?>"><?php echo html($article->title()) ?></a></h3>
          <p>
            <?php echo $article->author() ?>
          </p>
        </article><?php endforeach ?>
      </div>
      <aside class="text">
        <h3>All Tags</h3><?php $tags = $page->children()->visible()->pluck('tags', ',', true); asort($tags);?>
        <ul class="tagcloud"><?php foreach($tags as $tag): ?>
          <li><a href="<?php echo url('publications/tag:' . $tag)?>"><?php echo html($tag) ?></a></li><?php endforeach ?>
        </ul>
      </aside>
    </section>
<?php else : ?> // show the regular entry

Well, this might be a cheap workaround. Here’s what I did: I simply moved the code above into the new homepage template, since the /tag:something is appended to the base url. I just had to adjust the tag cloud accordingly. Here’s the code for those who might have the same issue.

<?php if(param('tag')): // show tag results ?>
    <?php $tag = urldecode(param('tag')); ?>
    <?php $articles = $pages->find('publications')->children()->visible()->filterBy('tags', $tag, ',')->flip()->paginate(10); ?>
    <div class="hero">
      <h1>&ldquo;<?php echo $tag ?>&rdquo;</h1>
      <div class="subtitle">Here are the publications we have found under this tag:</div>
    </div>
    <section class="content">
      <div class="text"><?php foreach($articles as $article): ?>
        <article>
          <h3><a href="<?php echo $article->url() ?>"><?php echo html($article->title()) ?></a></h3>
          <p>
            <?php echo $article->author() ?>
          </p>
        </article><?php endforeach ?>
      </div>
      <aside class="text">
        <h3>All Tags</h3><?php $tags = $pages->find('publications')->children()->visible()->pluck('tags', ',', true); asort($tags);?>
        <ul class="tagcloud"><?php foreach($tags as $tag): ?>
          <li><a href="<?php echo url('/tag:' . $tag)?>"><?php echo html($tag) ?></a></li><?php endforeach ?>
        </ul>
      </aside>
    </section><?php else: ?>

Anyhow… if someone has a better solution, I’m happy to hear it.
:smile: