Include post category in URL

Hello,

I have a new question :slight_smile:
I have a parent category with different sections including several posts.
Now, i dont’ create a post with the same name while they are not in the same section.
I would like post URLs to include the name of the section.

To get (for example):
• filmography/audio/rouge
• filmography/clips/rouge

I think that https://getkirby.com/docs/reference/panel/blueprints/page#preview__custom-link

What your best practice?

Why don’t you use subpages for these categories and put your posts into those categories? That would be the straightforward way.

Otherwise, you need to combine routes withpage models where you redefine the URL.

I’ll move this to a new topic.

I’m learn :slight_smile:

Since a new installation, I create one category with subpages for pages. That’s ok, each page go to a subpage folder. Good.

Maybe…
• in first page “category”, I would like show each block = one subpages > list of page.
• and of course, i create a new post from this same page.

I guess I need to adjust my blueprints sections to indicate a sub level?

When each post fits into exactly 1 category, I’ld setup my site architecture with a subfolder for the category, and in it all of ‘its’ posts (as @texnixe suggests).

When a post can be a member of multiple different categories, you can’t reflect that in the URL without creating duplicate content (which is a bad, bad thing). Then you’ld need to set up category-pages with generic slugs like /posts/category-id which lists the posts that are tagged for it. Your post-slug will probably be something generic like /post/post-id.

In my first post (in the forum) : “Rouge” is just a same post’name maybe is a different content. Not a duplicate content.

I think that isn’t really a problem as long as you define a canonical URL?

In any case, if each post has one category, a page structure like this makes absolute sense and saves you the extra mile to create models and routes:

/content
  /filmography
    /audio
      /post-1
      /post-2
    /clips
      /post-3
      /post-4

etc. That way, your URLs with the categories are created automatically.

35

In “Filmography”, I would like show a list or create a post by subcategory :’(

Yes, you can do that, you need to set up section for the different category pages then.

What are those categories in that page, fields or sections? Please post your blueprint.

pages/filmography.yml

title: Filmography

columns:
  - width: 4/4
    fields:
      intro:
        label:
          fr: Intro
          en: Texte d'introduction
        type: textarea
        size: small

  - width: 1/6
    sections:
      filmography-audio:
        extends: sections/filmography-audio
        headline: 
          en: Audio
          fr: Audio
        create:
          - filmography-audio-single
        template:
          - filmography-audio-single
  - width: 1/6
    sections:
      filmography-clips:
        extends: sections/filmography-clips
        headline: 
          en: Clips
          fr: Clips
        create:
          - filmography-clips-single
        template:
          - filmography-clips-single
  - width: 1/6
    sections:
      filmography-live:
        extends: sections/filmography-live
        headline: 
          en: Live
          fr: Live
        create:
          - filmography-live-single
        template:
          - filmography-live-single

  - width: 1/6
    sections:
      filmography-movie:
        extends: sections/filmography-movie
        headline: 
          en: Movies
          fr: Movies
        create:
          - filmography-movie-single
        template:
          - filmography-movie-single
  - width: 1/6
    sections:
      filmography-hommage:
        extends: sections/filmography-hommage
        headline: 
          en: Tribute
          fr: Hommages
        create:
          - filmography-hommage-single
        template:
          - filmography-hommage-single
  - width: 1/6
    sections:
      filmography-interview:
        extends: sections/filmography-interview
        headline: 
          en: Interviews
          fr: Interviews
        create:
          - filmography-interview-single
        template:
          - filmography-interview-single

pages/filmography-audio

title: Filmography Audio

# Each page can have an icon that is shown in page listings when no preview image is available.
icon: 📝


# Custom descriptions of page statuses depending on use case
# More about page statuses: https://getkirby.com/docs/reference/panel/blueprints/page#statuses
status:
  draft: false
  unlisted:
    label: Hidden Page
    text: The page is not listed in the main menu
  listed:
    label: Menu Page
    text: The page is listed in the main menu

# Limit subpage display to certain templates in a page preset
pages:
  template: default

# A page preset can have a freely defined set of fields
# List of all available field types: https://getkirby.com/docs/reference/panel/fields
fields:
  audio_text:
    label:
      fr: Texte
      en: Text
    type: textarea
    size: small
  video:
    label:
      fr: Vidéo
      en: Video
    type: url
    icon: video
  audio_album:
    label:
      fr: Extrait de…
      en: Extract of…
    type: text
    width: 1/4
  audio_year:
    label:
      fr: Année
      en: Year
    type: number
    width: 1/4
  audio_real:
    label:
      fr: Réalisateur
      en: Real.
    type: text
    width: 1/4
    icon: user
  audio_tracktime:
    label: 
      en: Time
      fr: Durée
    type: time
    step: 1
    width: 1/4
  audio_credits:
    label:
      fr: Crédits supplémentaires
      en: Additionnal Comments
    type: textarea
    size: small
  cover:
    label:
      fr: Image
      en: Image
    type: files

sections/filmography-audio

type: pages
headline: Audio
template: filmography-audio-single
empty: No notes yet
layout: list
info: "{{ page.audio_year.toDate('Y') }}"

That looks good, the only missing piece is that your filmography-audio section doesn’t have a parent page. So you would have to use the category subpage as parent here. And of course for the other categories as well.

1 Like

I try without success…
sections/filmography-audio

type: pages
headline: Audio
template: filmography-audio-single
empty: No notes yet
layout: list
info: "{{ page.audio_year.toDate('Y') }}"
parent: kirby.page("filmography")

Should it be

parent: kirby.page('filmography').children.find('audio')
1 Like

Thanks, that’s Ok !!! :slight_smile: