We are trying to add specific code that shows up on the homepage, and doesn’t show up for tag:
routes. As it stands, any tag routes use the home.php
template.
We tried to add if ($page->isHomePage()):
with no luck.
Homepage: http://jfi-pw.partnerandpartners.com/
Tag Page: http://jfi-pw.partnerandpartners.com/tag:staff+picks
Here’s the routes section of the config:
'routes' => [
[
'pattern' => '(:any)/(:any)/image.png',
'action' => function ($base1, $base2) {
$page = page($base1.'/'.$base2);
if (!$page) {
return site()->visit(site()->errorPage());
}
if ($page->file('image.png')) return go($page->file('image.png')->url());
if ($page->hasImages()) return go($page->image()->url());
return go(site()->url().'/assets/images/pw-icon.png');
}
]
],
Site.php Controller:
<?php
return function($site, $pages, $page, $args) {
$collection = new Pages();
if ($page->isHomePage()):
$collection = $site->index()->listed()->filterBy('template','article');
$collection = $collection->sortBy('date', 'desc');
elseif ($page->template() == 'author'):
$collection = $site->index()->listed()->filterBy('authors', '*=', $page->autoid());
else:
$collection = $page->children()->listed()->sortBy('date', 'desc');
endif;
if ($page->title() !== "search") {
$articles = $collection->sortBy('date', 'desc');
}
if($tag = urldecode(param('tag'))) {
$articles = $site->index()->listed()->filterBy('tags', $tag, ',')->sortBy('date', 'desc', 'time', 'asc')->paginate(10);
} else {
$articles = $collection->paginate(10);
}
$pagination = $articles->pagination();
// Get the authors
$authors = [];
foreach($page->authors()->split() as $author):
$authors[] = page('authors')->children()->findBy('autoid', $author);
endforeach;
$tag = ucwords(kirby()->request()->params()->tag());
if ($tag != "") {
$top_title = "<span class='tag-title'>↳ {$tag}</span>";
} elseif ($page->template() == "search") {
$top_title = "Results for '" . $query . "'";
} elseif ($page->template() == "category") {
$top_title = "↳ " . $page->title();
} elseif ($page->template() == "author") {
$top_title = "➔ " . $page->title();
} else {
$top_title = "Phenomenal World";
}
return compact('authors', 'articles', 'pagination', 'top_title');
};