Forum

Thread tagged as: Question, Blog

Blog Post Slug

Hi Guys,

Is it possible to change the field that generates the Blog Slug? I want to have a custom field in the CMS that is used to create custom urls for each blog,

I've tried a few different ways of doing this from what I can find in the docs but not had any luck getting it to work.

Cheers

Chris

Chris Bell

Chris Bell 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The slug generation is hardwired for the blog, as it's a crucial field.

You should be able to ignore it and use your own field for that purpose though.

I have added this to my blog

<perch:blog id="postURLCustom" type="text" label="URL"  hidden="true"/>
<perch:blog id="postSlugCustom" type="slug" for="postURLCustom" surpress="true" />

Then in the settings set my blog post path to "/blog/{postSlugCustom}" and slug format to "{postURLCustom}" (I've tried various combinations of the fields on the settings). The blog isn't picking anything up in the URL however It's just empty url like this "/blog/ "

I guess I'm doing something wrong but can't figure out what.

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

In your page, are you then filtering based on that field? If not it'll be matching it against postSlug which will obviously fail.

No i'm not as not sure what you mean by filtering?

In my post_summary file I've changed the a tag to use the custom slug

<a href="<perch:blog id="postSlugCustom" />" rel="bookmark">
Drew McLellan

Drew McLellan 2638 points
Perch Support

What code do you have on your page for displaying a post? It should be something like:

perch_blog_custom([
    'filter' => 'postSlugCustom',
    'match' => 'eq',
    'value' => perch_get('s'),
]);