Parent permalink slug before CPT slug - wordpress

I'm currently busy making a FAQ for my website but i'm struggling with the permalink structure.
I have made a regular page where people can see an overview of the FAQs. I called that page Klantadvies.
I installed a Custom Post Type plugin and made a post type called faq. I also made a taxonomy which is called onderwerp.
Unfortunately the plugin won't allow me to have a page parent in the slug. So i'm wondering if it's possible to have my page slug (klantadvies) in front of the custom post type slug. For example:
http://mypage.com/klantadvies/faq/onderwerp
Thnx in advance!

Rather than using a plugin for your post types and taxonomies, I'd recommend you use these two solutions:
https://generatewp.com/post-type/
https://generatewp.com/taxonomy/
You can use those to create your Post Type and Taxonomies. Within each of those configs you're allowed to setup the slugs / URL structure that you want to use.
On top of that you're going to need to setup a custom rewrite rule to handle echoing out the values you're looking for on the appropriate layout.
https://codex.wordpress.org/Rewrite_API/add_rewrite_rule

Related

Multiple slugs in WP post

I am currently working on a blog section of a website that's powered by wordpress.
Currently post are defaulted to /blog/$postname%
however we have a select few post that do not need to be /blog/ they should be /news/%postname%
is it possible to do this in WP?
Also if it helps I am using CPT UI to make a custom post.
You can't change the base url for just a few posts but you can create a separate post type for the ones you want to be different. Using CPTUI you can set their base to be /news. In the CPTUI admin just set "Has Archive" to true and putting "news" in the input for the slug to use.

Post Types, Taxonomies and routing

I'm ready to give up on Wordpress.
I've got this issue. I have created a custom post-type via wp-types plugin. I can display it and display posts from it.
However, I have created a custom page with a custom template that renders the posts. I have done so because the site uses multiple languages, and I needed the url to be in that specific language.
Thus the post-type is not displayed through the standard archive-{post-type-name}.php file, but instead a custom template and a custom wordpress page.
Just because I need the urls to be in the same language as the given page language, example:
myurl.com/{name_in_one_language}
and
myurl.com/{name_in_another_language}
The issue with that is that my custom post-type has custom taxonomies attached to it. Before the posts are rendered I select the taxonomy and then render the rest of the page based on the taxonomy name. Example:
myurl.com/paintings/?category=category_name
|| or ||
myurl.com/paintings/?author=painting_author
The thing is that the client doesn't like that kind of custom url parameters. He is begging for me to change it to the following format:
myurl.com/paintings/{taxonomy}/{painting}
Where taxonomy is either authors name or art type. And the paintings page itself is just a middleware to select which post with the needed taxonomy needs to be displayed.
I have ran out of ideas of how to do it. Completely.
I tried going with the archive-{post-type-name}.php solution, have no clue how wp-types plugin rewrite works. Tried using the wordpress permalink syntax in the plugin, doesn't recognize it.
Basically what I need is the following: For my custom page that has a custom template that renders custom post-type with custom taxonomies to route in the following way:
myurl.com/{page-with-template-that-renders-custom-post-type}/{post-type-taxonomy}/{post}
I really find Wordpress difficult to work with, the way you have to inject code, handle routes, register types. It feels like you're just patching it together to make a horrible monster that spews code bile over everyone.
First, set your permalink settings to 'Post name'. Read through Wordpress' template hierarchy to understand how things work: https://codex.wordpress.org/Template_Hierarchy
If you create a taxonomy-{taxonomy-slug}.php template, you can then navigate to myurl.com/paintings/{taxonomy}/{taxonomy-term} and use the following within your template
$taxonomy = get_query_var( 'taxonomy' );
$term = get_query_var( 'term' );
.. and use those variables in your query.
A single-{post-type-slug}.php would be used to render the post itself.
I would argue that it is not advisable to include the taxonomy in the URL of the post as these could change, or you could have multiple terms associated with a post. But, if it's necessary, check out this article: http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks

WordPress: Same Permalink structure for pages, a custom post type and a taxonomy?

Is it possible to have the same permalink structure for pages, a custom post type and a custom taxonomy. The desired permalink for them all is http://sitename.com/{slug}
How can I achieve that?
You can use plugin custom permalink. By using this plugin you can set url as u want.
http://wordpress.org/plugins/custom-permalinks/
Short answer: Yes and No. You can code something up yourself, create some fancy .htaccess rules or use a combination of plugins.
See this post, despite its name, someone does suggest a plugin - I've used the plugin they talk about (wp-no-category-base), it does the job. Be aware that you could be asking for trouble doing this (for instance if you try to label a particular post with the same name as the category/custom taxonomy/etc - read the accepted answer here: https://wordpress.stackexchange.com/questions/42120/remove-slug-in-taxonomy-url):
Remove category & tag base from WordPress url - without a plugin
I'm fairly sure it handles custom post types - can't remember. If not, check out this:
https://github.com/markoheijnen/wp-no-taxonomy-base
Note: this code has not been updated in a long time.

Wordpress - Show parent category AND subcategory name in subcategory archive URL

I'm having some trouble with Wordpress category/subcategory archive URLs.
For example, I want to be able to display this archive: http://faroutmagazine.co.uk/wp/track-of-the-day while keeping its parent category in the URL, making it http://faroutmagazine.co.uk/wp/music/track-of-the-day
Previously, I was just getting a "This is embarrassing..." 404 message when accessing the /music/track-of-the-day URL (even though that's the one that was appearing in the View option under categories in the admin section of WP).
Now the View link in the admin area only shows me the /track-of-the-day URL, and this DOES display the category posts which is great, but I want it to include the parent category in the URL.
Is there anything I can do to the functions.php file or any plugins I can add to make this happen? Please bear in mind that there are multiple subcategory archives on this site, and they should all contain the parent category in the URL.
***UPDATE:
I actually have just set everything up a different way now using Pages and showing category archives on pages as it's taking up too much time. Thanks for your answer though. People telling me to use %category%/%postname% as the permalink structure are incorrect - yes, this works for the POST urls but not for the archive category of the subcategory which is the problem I was actually looking for help with. If anyone can provide an answer, it would be appreciated, but I am using this workaround now as this was taking up way too much time trying to figure out.
This happens because you chose category and subcategory from the right options tick boxes when editing the entry. Choose only the subcategory box in every entry and it will show the nested URL.
To make this happen you need to make some change in permalinks
go to Settings->Permalinks then select custom structure and use this syntax " /%category%/%postname%/ "in the field
Now save the settings and you can see the post url's using its category name in the permalink
Hope it helps :)
You should set hierarchical value to true when you are defining your taxonomy.
'rewrite' => array('slug' => 'mySlug', 'hierarchical' => true),
Then if you have a subcategory the url will be shown like this:
http://example.com/taxonomy/parentCategory/subCategory/
I found this sloution here:
https://wordpress.stackexchange.com/questions/155319/how-to-include-parent-terms-in-hierarchical-taxonomy-urls
Actually hierarchical subcategory archive permalinks are default in wordpress.
If you have a "pretty permalinks" structure selected in settings > permalinks, like /%postname% for example, then category and subcategory archive urls should default to something like:
yourdomain.com/category-base/category/sub-category/sub-sub-category
I had encountered a similar issue with a recent WP project, BUT I was using a plugin called WP No Base Permalink in order to get rid of my category and tag base slugs in my archive permalinks. When I deactivated the plugin, category hierarchy suddenly returned to my archive permalinks (luckily this project was still in development, otherwise, I would have had some major 404 problems).
I have not yet found/tested another plugin for eliminating category/tag base slugs that will also preserve hierarchy in sub/category archive urls, but it turns out that I do not need that functionality for my current project.
Instead I am using the base slugs blog-articles and blog-tags for the standard categories and tags in order to set the blog taxonomies apart from other taxonomies. Then I am using the plugin Types to create a custom post type and custom taxonomies for that post type. The Types plugin has an option in the advanced settings to set hierarchical taxonomy urls to true or false when creating a custom taxonomy.
Finally, I found a plugin called Remove Taxonomy Base Slug that effectively eliminates the default taxonomy term from the base slug of the taxonomy archive urls. And this, thankfully, does not interfere with the hierarchical sub/category urls, OR the base slugs for standard tags and categories.
So now, my blog categories/tags look like this:
yourdomain.com/blog-articles/category/sub-category/
or yourdomain.com/blog-tags/tag/
And my custom post type categories/tags look like this:
yourdomain.com/category/sub-category/ or yourdomain.com/tag/
Phew!
I hope this helps!
Setting Settings->Permalinks->Category base to '%category%' should give you what you want. According to WP doc:
Nested sub-categories appear as nested directories in the URI
See http://codex.wordpress.org/Using_Permalinks.
The Permalinks settings should be like /%category%/%postname%/ ..
If use custom permalinks settings as %postname% only, it will make your url in the form of .../category/subcategory.
You can use WordPress plugin to remove 'category' from url
http://wordpress.org/plugins/wp-no-category-base/
and then follow the instruction given by Maruti

custom post types wordpress

I have created a custom post type called show.. How do I tell wordpress to go to show.php for loading the content instead of single.php?
This is crucial since single.php does not carry the code for the extra added fields I have, thats why I want to use show.php
thanks
The WordPress docs say your template file must be single-show.php, not just show.php.
single-<post-type>.php
The single post template used when a single post from a custom post type is queried. For example, single-books.php would be used for displaying single posts from the custom post type books. index.php is used if the query template for the custom post type is not present.
1.Copy single.php.
2.Rename it single-show.php.
3.Now modify this template as per your requirement.

Resources