Rewrite wordpress custom taxonomy archive url - wordpress

I have many custom post types and custom taxonomies such as "video" custom post type and "video_category", "product" and "product_category" and so on...
All the products are displayed at website.com/shop but if I get to an archive the permalink become website.com/product_category/"categoryname" and the single post has a link like website.com/product/"productname".
I have googled and found out about link rewriting but... don't really know where to start.
I'd like to have the links above become website.com/shop/"categoryname" and website.com/"categoryname"/"productname".
I could simply change the taxonomy name to "shop" for the first case but that would not be really clean, those are categories after all.

Related

How to customize wordpress category page

I am working on a wordpress website.I used genesis theme. I created custom post type and custom taxonomy to this site.And also created some categories to this post type.I want to customize the category page i.e.http://example.com/taxonomy-slug/category-name. Can anyone know please let me know what changes are necessary to customize the category page.
"taxonomy-{taxonomy}-{term}.php – If the taxonomy is sometax, and taxonomy’s term is someterm, WordPress will look for taxonomy-sometax-someterm.php. In the case of post formats, the taxonomy is ‘post_format’ and the terms are ‘post-format-{format}. i.e. taxonomy-post_format-post-format-link.php for the link post format.
taxonomy-{taxonomy}.php – If the taxonomy were sometax, WordPress would look for taxonomy-sometax.php."
source https://developer.wordpress.org/themes/basics/template-hierarchy/
so if you have for example custom taxonomy with slug "color" and have term with name "red" you just create taxonomy-color-red.php.

WordPress custom post templates

I am new in WordPress world. I created custom post successfully and I displayed it on page template page. Now I want to use taxonomy-{category}.php and single-{post}.php for displaying custom post but I am confused in taxonomy page and single page. How can I achieve this?
In taxonomy-{category}.php here category means our custom category name or others?
In single-{post}.php here post means custom post name or others?
See the Template_Hierarchy on the Wordpress Codex
taxonomy-{taxonomy}.php - If the taxonomy were sometax, WordPress
would look for taxonomy-sometax.php
single-{post_type}.php - If the post type were product, WordPress would look for single-product.php.
Example:
For post_type
When on an online store custom post type in the backend, the URL would be wp-admin/edit.php?post_type=store.
So the post_type in this case is store, which means I will name my file single-store.php
For taxonomy
When on the Categories page for the online store in the backend, the URL would be edit-tags.php?taxonomy=store_categories&post_type=store
So the taxonomy file would be taxonomy-store_categories.php
In taxonomy-{category}.php here category means our custom category name or others?
taxonomy-{category}.php here category means your custom category(taxonomy)
In single-{post}.php here post means custom post name or others?
single-{post}.php here post means custom post type name

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

Wordpress custom post permalink structure inside custom post permalink

I have custom post structure like this:
mysite.com/custompostname/customposttitle
and i need to have one more custom post type that have depedency with myfirst custom post type so my permalink would be:
mysite.com/custompostname/customposttitle1/custompostname2/custompost2title1
mysite.com/custompostname/customposttitle1/custompostname2/custompost2title2
mysite.com/custompostname/customposttitle2/custompostname2/custompost2title3
mysite.com/custompostname/customposttitle2/custompostname2/custompost2title4
etc..
I to have news section for my custom posts in permalink, for example:
mysite.com/companies/company1/news/news1
Is there way to achieve this?
You can customise the permalink for a custom post type, but it needs to be hardcoded in the rewrite parameter given to register_post_type. You could use categories to achieve the same thing though: set up a taxonomy for the first custom post type and then use the posts to create a custom taxonomy for the second CPT (i.e. the posts from the first CPT would become the categories for the second).
So you would add something like this pseudo-code to the edit page for the second CPT:
get all posts of type 'CPT1'
loop through them to create a list of checkboxes
display in a metabox
save the result
There are still hoops to be jumped through to get those URLs going to the right place, but it's a start.

Same string for custom page type and slug

I have a custom post type team and a page titled "Team" whose slug is also team.
Team page is assigned to page-team.php (template name "Team"). team custom post type uses single-team.php template file. When my browser points to /team it uses the index.php template instead of the page I wanted (the team page file).
How can I correct this?
From the Wordpress Codex: Post Types section URLs:
The new post type will also get its own special section of the site layout. In the above example, posts of this new "product" type can be displayed at http://example.com/product/%product_name% (where %product_name% is the URL-ized name of your product, i.e. http://example.com/product/foobrozinator.) You can see this link appear in the edit pages for your new type, just like other posts.
This means:
Your custom type team pages are all reachable under http://example.com/team/%slug%.
Since your slug is team the url is http://example.com/team/team.
Makes sense. The Codex page about custom post type is worth a good and thorough read.
Edit: If you aren't happy with /team/team, try the Custom post type permalink plugin.

Resources