Custom plugin to append article category to the permalink url
3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: April 6, 2016 (RSS)
By adventure - April 5, 2016
I found this post https://www.interactivetools.com/forum/forum-posts.php?postNum=2236916
I created a new folder called permalink_custom and put the code from the above post in that folder as permalink_custom.php
I activated my new plugin, but nothing happens when I save an article post...I am wondering how custom plugins work and exactly how I need to set this up inorder to put the category field from my article table into the permalink url.
thanks,
Jill
By adventure - April 6, 2016
so I got the custom code to fire but now I am getting an error that says
Permalink can only contain these chars (a-z0-9/-.)!
This is the code:
// create custom permalink on first save of record
if ($tableName == 'newsroom' && !$oldRecord) {
echo $prefix . @$_REQUEST['category'] .'/'. @$_REQUEST['title'];
$_REQUEST['permalink'] = $prefix . @$_REQUEST['category'] ."/". @$_REQUEST['title'];
}
in my testing I add the echo to see what was being passed in and it does not include any bad characters:
news/Video Advertising/Test Permalink Permalink can only contain these chars (a-z0-9/-.)
By Damon - April 6, 2016
Hi Jill,
The Permalinks plugin isn't designed to dynamically add categories to the permalink URLs.
In your test example, news/Video Advertising/Test Permalink Permalink, spaces is what is not allowed.
The example plugin code Dave posted in the other thread was only a starting point which would need more code and testing to make work. There are several issues that have to be considered and resolved as Dave mentioned:
Note that overriding the permalinks field value will prevent the user from setting a custom permalink. Another way to do it might be to write a plugin that used javascript to update the permalink field when the user selected/changed categories, but you'd need to think about what it should do when adding records vs editing, etc.
Are you interested in getting a quote from our consulting department in getting this setup?
Let me know.
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/