One Post in Multiple Pages VIA Tags or Categories

Trying to figure out the best way to use one post through multiple pages. I’m trying to prevent needing multiple copies of the same post. Mainly, I want less work for the eventual admin of the site. This is for a portfolio site for multiple artists.

For example:

  • I want to have a post entitled “Dancers” that is a subpage of a specific artist.
  • I also want this same post entitled “Dancers” to show up on a page containing all of the posts tagged “Animation”

I want to be able to present this one piece two different ways, one labeled under an individual artist but also grouped together with all the like pieces.

The content menu I have in my head would be like so:

  • List of Artists
    • Individual Artists Page 1
      • Post 1 (Tagged: Animation)
      • Post 2 (Tagged: Commercial)
    • Individual Artists Page 2
      • Post 3 (Tagged: Commercial)
      • Post 4 (Tagged: Animation)
  • Animation Page (Only posts tagged ‘animation’)
    • Link to Post 1
    • Link to Post 4
  • Commercial Page (Only posts tagged ‘commercial’)
    • Link to Post 2
    • Link to Post 3

With Wordpress I would be able to filter categories and display items site wide, rather than just under the single subpage. Is that possible with Kirby? It seems like I could use the pluck function on the animation page to find any post tagged Animation, but it doesn’t seem to work that way.

With Kirby you can also create collections of content, plucked site-wide. E.g.: you could do something like below (considering the following content structure):

  • Artists page (template: artists)
    • artist 1 page (template: artist)
      • Post 1 (Tag: animation) (template: post)
      • Post 2 (Tag: Commercial) (template: post)
    • artist 2 page (template: artist)
      • Post 3 (Tag: animaton) (template: post)
      • Post 4 (Tag: Commercial) (template: post)
  • Animation page (template: overview)
  • Commercial page (template: overview)

You can merge collections of pages in a controller.

Thus you can use something like this in the “overview”-controller:

<?php 

return function($site, $pages, $page) {
    // Get all posts
    $posts = new Pages();
    foreach(page("artists")->children()->visible() as $artist) {
        $posts->add($artist->children()->visible());
    }

    // Apply filter set in the content of the "overview"-page in the "filterkey" field (e.g. "animation")
    $posts = $posts->filterBy('tags', $page->filterkey()->value(), ',');
    
    return compact("posts");
};

Now you have a $posts variable in your overview-template you can use to create the links.

Disclaimer: Code is hypothetical & untested.

This can achieved with less code:

<?php 

return function($site, $pages, $page) {
    // Get all posts
    $filterKey = $page->filterkey()->value(); // or from a parameter
    $posts = page('artists')->grandChildren()->visible()->filterBy('tags', $filterKey, ',');

    return compact("posts");
};

The question is if you really want different pages for each filtered collection. Because you could use parameters to filter a complete collection of all posts (provided, that you want to have such a page with all posts).

But @bvdputte’s code above was a good example to show one of Kirby’s method for creating new collections. There are other methods like merge(), prepend() or append().

The pluck() method you mentioned above is useful if you want to fetch all the tags of all posts, for example, to create a tag cloud.

SEO could be a good reason, but then you have to have enough unique content backing that…

Yes, that could be one reason. Also, if you want these pages to appear in the navigation, it makes things easier.

@texnixe & @bvdputte that worked beautifully. Thanks a lot.

As far as reason, @texnixe hits it right on the head, easier navigation. But also we want to show artists separately, but also show all of the work as one larger company.