How to internal linking to blog post

I’m using the internal linking within the markdown editor:
[Post](october://entry-edcd102e-0525-4e4d-b07e-633ae6c18db6@link/173?cms_page=blog%2Fpost)

CMS Page setup of the Blog Post:

url = "/:category/:subcat/:slug"
layout = "blog"
title = "Blog Post"
meta_title = "{{ blog.title }} - Blog"

This is how I render the markdown content

{% if post.entry_type == 'markdown_post' %}
  {{ post.content|md|content }}
{% else %}
  {{ post.content|content }}
{% endif %}

Output link to blog post:
http://localhost:8888/site/en/default/default/whv-australia

I’ve tested to internal link directly to a category.
Output link to category:
http://localhost:8888/site/en/oceania/australia

And apparently, this issue is in the Sitemap as well (link to )

Does anyone know how to solve this?

Hey @kevinvermeulen

We’ve added a solution to this in v3.6.1

In the provided example, you could add the following to your blueprint:

pagefinder:
    replacements:
        subcat: categories.0.slug
        category: categories.0.parent.slug

The above selects the first category for subcat and the first categories’ parent as the category. It will still return “default” if the category has no parent…

So a better approach might be to use a wildcard URL along with a structure for the categories to enable the fullslug attribute that builds a slug containing a path back to the parent category.

url = "/:category*/:slug"

Then in YAML

pagefinder:
    replacements:
        category: categories.0.fullslug

Here is the relevant documentation, I hope this helps!


Page Finder Configuration

The page finder will automatically resolve the id, code, slug and fullslug attributes and use them as replacements in the page URL parameters. You may specify custom replacements as an array using the pagefinder properties, including the optional context from above.

pagefinder:
    context: list
    replacements: []

Each replacement key should match a URL parameter name and use a dot notation path to the attribute value. Take the following URL example for a blog post page.

url = "/blog/post/:author/:category/:slug/:id"

The following replacements will set the :author parameter to the related author slug attribute value, and the :category parameter to the first related categories slug attribute value.

pagefinder:
    replacements:
        author: author.slug
        category: categories.0.slug
1 Like

Thanks for the reply. Yes this makes really sense and very helpful!

I added the replacements (both ways as described) in the Blueprint of the Sitemap (demo theme) in OC 3.6.2.
Unfortunately, it doesn’t allow me to do it as I get an error. Also I tried in the top of the Blueprint unsuccessfully under pagefinder.

uuid: 6743a1c3-3e57-4cfa-a886-e0c0a277fd71
handle: Site\Sitemap
type: structure
name: Sitemap
drafts: false
pagefinder: false 

uuid: 6743a1c3-3e57-4cfa-a886-e0c0a277fd71
handle: Site\Sitemap
type: structure
name: Sitemap
drafts: false
pagefinder: false      

structure:
    maxDepth: 1

navigation:
    parent: settings
    icon: icon-sitemap
    description: Specify pages to appear in the sitemap for your website.
    category: CATEGORY_CMS

fields:
    reference:
        label: Reference
        type: pagefinder
            replacements:
                subcat: categories.0.slug
                category: categories.0.parent.slug
        

    priority:
        label: Priority
        commentAbove: The priority of this URL relative to other URLs on your site.
        type: radio
        inlineOptions: true
        options:
            '0.1': '0.1'
            '0.2': '0.2'
            '0.3': '0.3'
            '0.4': '0.4'
            '0.5': '0.5'
            '0.6': '0.6'
            '0.7': '0.7'
            '0.8': '0.8'
            '0.9': '0.9'
            '1.0': '1.0'

    changefreq:
        commentAbove: How frequently the page is likely to change.
        label: Change Frequency
        type: radio
        inlineOptions: true
        options:
            always: Always
            hourly: Hourly
            daily: Daily
            weekly: Weekly
            monthly: Monthly
            yearly: Yearly
            never: Never

    nesting:
        label: Include nested items
        shortLabel: Nesting
        comment: Nested items could be generated dynamically by supported page references.
        type: checkbox

    replace:
        label: Replace this item with its generated children
        comment: Use this checkbox to push generated menu items to the same level with this item. This item itself will be hidden.
        type: checkbox
        column: false
        scope: false
        trigger:
            action: disable|empty
            field: nesting
            condition: unchecked

Hey @kevinvermeulen

The replacements go on the linked blueprint. So if you are linking to a Blog\Post

uuid: edcd102e-0525-4e4d-b07e-633ae6c18db6
handle: Blog\Post
name: Post
type: stream

pagefinder:
    context: item
    replacements:
        category: categories.0.slug
        subcat: categories.0.parent.slug

fields: []

:pray:t3: Thanks a lot mate!
This is working perfectly and was the missing link for me.

I really enjoy working with OC especially with Blueprints nowadays!

1 Like

My pleasure. That’s great to hear as well :slight_smile:

1 Like

Hey

I’m trying to repeat this trick on a blog page in a demo theme and I’m not getting the same result. What could be the problem?

And I get a link - blog/post/default/nemo-enim-ipsam

page

url = "/blog/post/:category/:slug"
{% if post is empty %}
    {% do abort(404) %}
{% elseif post.slug and post.slug != this.param.slug %}
    {% do redirect(''|page({ slug: post.slug }), 301) %}
{% endif %}

Yml

uuid: edcd102e-0525-4e4d-b07e-633ae6c18db6
handle: Blog\Post
type: stream
name: Post

pagefinder:
    replacements:
        category: categories.0.slug

customMessages:
    buttonCreate: New Post

primaryNavigation:
    label: Blog
    icon: octo-icon-file
    iconSvg: modules/tailor/assets/images/blog-icon.svg
    order: 95

navigation:
    label: Posts
    icon: octo-icon-pencil
    order: 100

groups:
    regular_post:
        name: Regular Post
        fields:
            content:
                tab: Edit
                label: Content
                type: richeditor
                span: adaptive

            _blog_post_content:
                type: mixin
                source: Fields\BlogContent

    markdown_post:
        name: Markdown Post
        fields:
            content:
                tab: Edit
                label: Content
                type: markdown
                span: adaptive

            _blog_post_content:
                type: mixin
                source: Fields\BlogContent

You need to add context: item under pagefinder, like this

pagefinder:
    context: item
    replacements:
        category: categories.0.slug
        subcat: categories.1.slug

I added this but it still doesn’t work for me, I get the link /blog/post/default/consectetur-adipiscing-elit

uuid: edcd102e-0525-4e4d-b07e-633ae6c18db6
handle: Blog\Post
type: stream
name: Post

pagefinder:
    context: item
    replacements:
        category: categories.0.slug

@9607801 are you running the latest version?

yes I am using the version 3.6.4

If it still says “default” then it means the categories relationship is empty, so categories.0 is returning null.

this code shows the category on the blog page, the category is linked to the post. I don’t understand what the problem could be.

 {% for category in post.categories %}
                                <a href="{{ 'blog/category'|page({ slug: category.slug, id: category.id }) }}">{{ category.title }}</a>{{ not loop.last ? ',' }}
                            {% endfor %}

Agreed, it should work, since everything looks fine from here.

I was never able to get the category in the blog page url. Below I will describe my steps in detail. Please tell me am I doing it right or am I missing something?

I created a clean install of version 3.6.5. I’m using the default Demo theme and blog.

On the blog page I entered the URL - /:category/:slug

Next in Tailor I add:

pagefinder:
    context: item
    replacements:
        category: categories.0.slug

As a result, I get a url like - /default/consectetur-adipiscing-elit

Please tell me what could be the problem?

This might be the part we are missing, where are you getting the URL from; are you clicking the Preview button in Editor, in Tailor, using the |link or |content filters?

Can you show us what you see when you click on CategoryPost?

@daft , it is not working anymore in the sitemap.
It only shows a Post Entry and not All Post Entries as an option.
This happened since the newest update 3.6.9.

@kevinvermeulen

In the Post entry, does it have pagefinder set in the blueprint at the root level?

This is the blog/post.yaml blueprint. Haven’t changed anything.

uuid: edcd102e-0525-4e4d-b07e-633ae6c18db6
handle: Blog\Post
type: stream
name: Post
drafts: true
# multisite: true
multisite: sync
pagefinder:
    context: item
    replacements:
        category: categories.0.slug
        subcat: categories.1.slug

customMessages:
    buttonCreate: New Post

primaryNavigation:
    label: Blog
    icon: octo-icon-file
    iconSvg: modules/tailor/assets/images/blog-icon.svg
    order: 95

navigation:
    label: Posts
    icon: octo-icon-pencil
    order: 100

# groups:
#     markdown_post:
#         name: Markdown Post
fields:
    content:
        tab: Edit
        label: Content
        type: markdown
        span: adaptive

    _blog_post_content:
        type: mixin
        source: Blog\PostContent

    SEO:
        type: mixin
        source: Blog\SEO