Custom Post Type/Taxonomy navigation and permalinks
-
Hi Guys n’ Gals,
I’m new to WordPress and must say that I love it! So much so I’ve stopped development on my own CMS and converting my existing websites!
The Problem I’m having
I have the same 2 basic requirements for all my sites that I didn’t expect to find so difficult!- To have a main menu item called ‘News’ (pemalink: /news/) with child items ‘Latest News’ (pemalink: /news/latest-news/) and ‘Newsletters’ (pemalink: /news/newsletters/). Posts permalink should also be like this (/news/latest-news/post-slug)
- To create news posts in a Custom Post Type so i can separate them from other posts in the Admin interface
Shouldn’t be too hard should it?
So i’ve created the Custom Post Type and Tax as follows
[ Moderator note: please wrap code in backticks or use the code button. ]
register_post_type( 'post-news', array( 'labels' => array( 'name' => __( 'News' ), ), 'public' => true, 'has_archive' => true, 'capability_type' => 'post', 'supports' => array('title','editor','revisions','thumbnail','excerpt') ) ); register_taxonomy( 'tax-news', 'post-news', array( 'label' => __( 'News Categories' ), 'rewrite' => array( 'slug' => 'news'), 'hierarchical' => true, 'show_ui' => true, 'show_admin_column' => true, 'capabilities' => array('assign_terms') ) );
Then set-up custom permalinks like this
/%category%/%postname%/
now i want to set-up the menu in Appearance > Menus
Ahh… i can’t add the root taxonomy OR the custom page type to create the parent ‘News’ item on the menu. So here lies the problem.
Attempt 1,628
i know i’ll create a page template for the parent item. But it has to have a different slug to ‘news’, as news is already taken, so i can’t have my permalinks how i want them. hmmAttempt 3,440
i know i’ll find a plugin that lets me add my custom post type archive to the menu. Custom Post Type’s Archive in WP Nav Menu.This is the closest solution. Everything works great (even the menu items stay highlighted when navigating down from main menu item > sub menu item > post).
BUT the permalinks are as follows:
Click on News > /custom-post-type-slug/
Click on Latest News > /custom-taxonomy-slug/term-slug/
Click on Post > /custom-post-type-slug/post-slug/I hope someone can help as i’m tearing my hair out!
Muchas Gracias!
Harv[No bumping. If it’s that urgent, consider hiring someone.]
- The topic ‘Custom Post Type/Taxonomy navigation and permalinks’ is closed to new replies.