Custom URL
-
Currently URL structure is like this:
http://yourblog.com/movies/fight-clubI want every post URL to have a custom value like this:
http://yourblog.com/movies/fight-club-valueI can achieve this for default wordpress posts by changing permalink structure in wordpress settings:
http://yourblog.com/%postname%-value/
But obviously it doesn’t work for WPMovieLibrary movie posts. I was looking through plugin files but couldn’t figure this out. Any help appreciated.
-
Hi there,
It can’t work on movies indeed as most of the permalink structures are hard-corded in the plugin. That’s kind of poorly handled and we’ll fix this in version 2.0.
In the meantime you can edit the plugin’s rewrite rules in the
register_permalinks()function of theincludes/class-wpml-utils.phpfile and add you custom value to the regular expressions you want. Don’t forget to reload the dashboard’s “Permalinks” page so the changes are effective!Unfortunatelly, I don’t understand PHP at all. Can you tell me which line I am supposed to edit?
Sure, please try changing line 122 from:
$movies . '/([^/]+)/?$' => 'index.php?movie=$matches[1]',To:
$movies . '/([^/]+)-your_value/?$' => 'index.php?movie=$matches[1]', $movies . '/([^/]+)-your_value(/[0-9]+)?/?$]' => 'index.php?name=$matches[1]&page=$matches[2]', $movies . '/([^/]+)-your_value/page/?([0-9]{1,})/?$]' => 'index.php?name=$matches[1]&paged=$matches[2]',Let me know how this works!
For some reason, it didn’t work. My already published movies started getting 404 Page Not Found and new ones still had the same old permalink structure without custom value added.
It does work on my test installations; did you reload the Settings > Permalinks page to apply the change?
I did reload Permalinks page it had no effect. Tried it on 2 different WordPress installs and still didn’t work.
By the way, the code I have to change is on line 120 in my version of the plugin. I use v1.2.2.Server info:
Apache version 2.2.29
PHP version 5.3.29
MySQL version 5.5.36-cll-lveI hope v2.0 is not too far away. I really need this fixed as soon as possible.
I’m afraid there’s still some work to do on v2.0 before we can think of delivering a stable release…
Here’s an edited v1.2.2
class-wpml-utils.phpthats works everywhere I tested it, see if it works for you: https://gist.github.com/CaerCam/1e0f68c36ab45f060df3 Edit your custom value at line 113.Note: this should only make the links work with or without the suffix; to generate permalinks including your suffix, add this to your theme
functions.phpfile: https://gist.github.com/CaerCam/773f048663082e4c4b00That being said, from I just saw of your website the suffix seems to work, doesn’t it?
I added suffixes manually. I want URL to include my suffix automatically when creating a new movie post. I’ll try your suggestions.
Now it seems to be working! It doesn’t show suffix added in dashboard when creating a movie post, but when movie is published it has suffix added. Thanks for helping me out!
Don’t mention it! I noticed the suffix doesn’t show in the post editor, this is really a quick as I have virtually no idea on how to apply to movies the same rewrite rules as regular postsβ¦ That’s something I’ll be looking for to learn and implement in v2 π
Maybe this is a stupid question, but what is the reason why this plugin uses custom post types? Using regular wordpress posts would solve many compatibility problems and would work with any theme out there. It would be nice to have an option to just import movie information in to regular wordpress post.
That’s no stupid question; the simplest answer is that it makes it easier to develop and use in numerous ways. There are tools inside WordPress that make it much easier to use custom post types rather than regular posts you would have to constantly separate from movies before doing anything; using a CPT you can target actions on this post type only and leave all other post types aside, affect custom taxonomies to this CPT only, define metaboxes, etc…
The compatibility issue in another part of the problem, but I tend to see it the other way: more often than not, compatibility issues come from themes that doesn’t support custom post types or handle them poorly; but since the plugin uses regular WordPress techniques, every theme should work smoothly with it. Technically CPT are in all points similar to regular posts, except for the
post_typefield in the database that’s set to ‘movie’ instead of ‘post’; it’s really easy for theme developers to adapt, but obviously a lot of them just don’t think about it when working on a theme.All considered, it is much more easier and cleaner to use a custom post type, even though compatibility with some themes can require a few tweaks π
Thanks for your clear explanation, now I understand about WordPress a bit more.
Hi,
I’m a bit lost. How can I apply these changes to current plugin version?
The topic ‘Custom URL’ is closed to new replies.