Using collections but keeping an index with all the posts

Hello team,

Preamble

I am a newcomer to Ghost CMS and I’m really thrilled about it.
I come from an 8y old WP and was looking for something more straightforward, fast, sleek. I’m still in the process of setting up my Ghost blog, after quite a painful migration (zip archive was too big for import, could not increase PHP limits enough, ended up with uploading the json after some fixes in it, managed to clean most tags, still have to reupload and integrate my pictures).

Context:
Sorry if it’s been answered before but I could not find the fix.
I’m trying to use collections in order to separate my content at URL level and it went well. But it kinda messed my pagination up.

This is my routes.yaml file:

routes:

collections:
  /musique/:
    permalink: /musique/{slug}/
    template: custom-collections
    filter: primary_tag:musique
  /photo/:
    permalink: /photo/{slug}/
    template: custom-collections
    filter: primary_tag:photo
  /moto/:
    permalink: /moto/{slug}/
    template: custom-collections
    filter: primary_tag:moto
  /carnets-de-voyage/:
    permalink: /carnets-de-voyage/{slug}/
    template: custom-collections
    filter: primary_tag:carnets-de-voyage
  /les-petites-videos/:
    permalink: /les-petites-videos/{slug}/
    template: custom-collections
    filter: primary_tag:les-petites-videos
  /:
    permalink: /{slug}/
    template: index

taxonomies:
  tag: /{slug}/
  author: /auteur/{slug}/

I used another template just to be sure it would not interfere but I actually duplicated index.hbs and renamed the copy.

My problem:
The / condition being last, it misses every post already filtered before. If you go on my blog, the homepage is / and calling index.hbs, and the first page is empty.
I would like my index to show all the posts, newest first, keep the pagination full and working, but also keep the ability to use the collections with the distinct URLs.

My question:
Do you know how I can achieve this? Should I be using channels? If so, can I keep my automatic primary-tag based URL categories for the related posts?:sweat_smile:

Thank you for your time/help and kudos to the team.
:v:

Installation details
  • What’s your URL? https://pianographe.fr
  • What version of Ghost are you using? [3.15.3]
  • What browser? Chrome Version 81.0.4044.138 (Build officiel) (64 bits)

Hey @pianographe :wave:
Short answer is yes, this is what Channels is for :blush:. Channels let you produce post list views of any posts but it doesn’t make them exclusive, and lets the posts respect their collection permalinks. More documentation on Channels can be found here:

It’s a filtered slice of content from across your site, without modifying the content itself.

Hope this helps!

1 Like

Thank you for your quick answer, seems like it’s working as expected!

Edit:
Actually, I found out that my posts URLs are not synced anymore to the primary-tag they belong to, they have the permalink structure mywebsite[dot]com/$slug
I would like to get a “category” or so in the URL.

For example, I have several posts about photography (primary) tagged “photo”. I’d like them to:

  1. :white_check_mark: be displayed with all the other posts on the Index page, order newest first
  2. :white_check_mark: be channeled though a “photo” tag to quickly access them
  3. :x: get a path like mywebsite[dot]com/photo/my-post-about-photo-nb1(just like with the collections)

Is there any way to have this “hybrid” feature? 1 and 2 are OK but 3 is missing now…

Thank you for your help.

Can you please share your updated routes.yml?

Hello,

Sure:

routes:
  /musique/:
    controller: channel
    filter: primary_tag:musique
    #permalink: /musique/{slug}/
  /photo/:
    controller: channel
    filter: primary_tag:photo
    #permalink: /photo/{slug}/
  /moto/:
    controller: channel
    filter: primary_tag:moto
    #permalink: /moto/{slug}/
  /carnets-de-voyage/:
    controller: channel
    filter: primary_tag:carnets-de-voyage
    #permalink: /carnets-de-voyage/{slug}/
  /les-petites-videos/:
    controller: channel
    filter: primary_tag:les-petites-videos
    #permalink: /les-petites-videos/{slug}/

collections:
  /:
    permalink: /{slug}/
    template: index

taxonomies:
#  tag: /{slug}/
#  author: /auteur/{slug}/

I tried to use the permalink attribute but it had no effect so I commented involved lines. I then rolled back (to collections) as having structured URL is very important to me (I like my stuff sorted and I’m using Disqus with old comments from WP that can only be displayed if the URL is the same).

At the end of the day, my preferred choice would be using collections and having the possibility to display a homepage listing all the posts, no matter in which collection they are, so that visitors could identify the latest publications at a glance :slightly_smiling_face:

Try this:

routes:
  /:
    controller: channel
    template: index

collections:
  /musique/:
    permalink: /musique/{slug}/
    template: custom-collections
    filter: primary_tag:musique
  /photo/:
    permalink: /photo/{slug}/
    template: custom-collections
    filter: primary_tag:photo
  /moto/:
    permalink: /moto/{slug}/
    template: custom-collections
    filter: primary_tag:moto
  /carnets-de-voyage/:
    permalink: /carnets-de-voyage/{slug}/
    template: custom-collections
    filter: primary_tag:carnets-de-voyage
  /les-petites-videos/:
    permalink: /les-petites-videos/{slug}/
    template: custom-collections
    filter: primary_tag:les-petites-videos

# NOTE: if you plan on having posts without any of the above primary tags, you need to add a collection here to "catch" the posts that weren't caught by the other filters

taxonomies:
  tag: /{slug}/
  author: /auteur/{slug}/

I’m not 100% sure if you need to add a filter for the route

2 Likes

Thank you so much, this is it ! :pray: The best of both worlds, to me.

There are still many broken images being fixed one by one :sweat_smile: but curious cats can see the result by following the link provided in the first post.

Thanks again and have a nice day!

2 Likes

Are you referring to the images missing on pages like this? https://pianographe.fr/photo/au-revoir-d800-bonjour-x100t/

Something may have happened with your migration from WordPress. Either the images weren’t in the export, or you didn’t copy over all your photos from the server you had WordPress installed on.

The image paths don’t get changed when they are ported over to Ghost, however Ghost will automatically produce additional image sizes for performance when the images are requested :blush:

1 Like

Hey David,

Yes, it’s perfectly normal, thank you for your concern.

I exported the full WP blog via the tool, but the result was 720MB and my PHP upload limit was 512MB, without exception (confirmed with my web support) because I’m on shared hosting (#teamPassenger).

Therefore, I used the json file alone to at least import the articles, knowing that I would have to redo all the media management. Luckily for me, I don’t have hundreds of articles, but mainly a few long travel diaries with pictures (like this one: https://pianographe.fr/carnets-de-voyage/new-york-city-floride/).

I could have recovered the tree structure and the files of the WP installation to keep the same paths, but I preferred to recover only the original photos and reinstall them cleanly on Ghost, to free myself from the “chaotic” management of WP with its 6 to 10 different dimensions for each image. I see it as an opportunity to go back in my memories and to have a well laid out content, even if it will take me some time.

1 Like