I don’t know your code, but let’s assume we use the Starterkit’s blog controller as a starting point (leaving out the pagination etc.)
So, this is the blog controller:
<?php
return function($site, $pages, $page, $args) {
if(isset($args['results'])):
$articles = $args['results'];
else:
$articles = $page->children()
->visible();
endif;
return compact('articles');
};
(Notice that we use a fourth argument $args
that, if it exists, gets additional data from the route)
This is the route:
c::set('routes', array(
array(
'pattern' => 'tag/(:any)',
'action' => function ($tag) {
$p = page('blog');
$children = $p->children()->visible();
// filter articles by tag using the filter with callback method
$results = $children->filter(function($child) use($tag){
// convert each tag item using the str::slug method
$tags = array_map(function($tag) {
return str::slug($tag);
}, $child->tags()->split());
// check if the given tag is in the modified tags array
return in_array($tag, $tags);
});
$data = [
'results' => $results
];
return array('blog', $data);
}
)
));
According to your post above, you want to remove the blog
part from the URL when calling your tags. If that was a mistake, you have to add it to the route. I actually think, the route should still contain the blog
part, otherwise it’s rather confusing for the user.
Make sure that you use the new tag URL in your tag links. You can use a page model for this.