I won’t lie – I don’t know php but I enjoy digging around trying to find ways to customize themes so that they behave how I want them to. Any help would be very much appreciated.
What I am trying to do:
There is a section in a wordpress theme I am using which allows you to publish portfolios.
The URL for any portfolio page would be:
mysite.com/portfolio/example-portfolio
When creating a new portfolio, you are given the option to assign a portfolio category, much in the same way as when you create a new post.
I would like to be able to have my portfolio URL’s appear like this:
mysite.com/portfolio-category/example-portfolio
I have highlighted an area of code I suspect might be editable to allow for this, but that is where my adventure sadly ends 🙁
Here is the code:
function mysite_post_types() {
register_post_type('portfolio', array(
'labels' => array(
'name' => _x('Portfolios', 'post type general name', MYSITE_ADMIN_TEXTDOMAIN ),
'singular_name' => _x('Portfolio', 'post type singular name', MYSITE_ADMIN_TEXTDOMAIN ),
'add_new' => _x('Add New', 'portfolio', MYSITE_ADMIN_TEXTDOMAIN ),
'add_new_item' => __('Add New Portfolio', MYSITE_ADMIN_TEXTDOMAIN ),
'edit_item' => __('Edit Portfolio', MYSITE_ADMIN_TEXTDOMAIN ),
'new_item' => __('New Portfolio', MYSITE_ADMIN_TEXTDOMAIN ),
'view_item' => __('View Portfolio', MYSITE_ADMIN_TEXTDOMAIN ),
'search_items' => __('Search Portfolios', MYSITE_ADMIN_TEXTDOMAIN ),
'not_found' => __('No portfolios found', MYSITE_ADMIN_TEXTDOMAIN ),
'not_found_in_trash' => __('No portfolios found in Trash', MYSITE_ADMIN_TEXTDOMAIN ),
'parent_item_colon' => ''
),
'singular_label' => __('Portfolio', MYSITE_ADMIN_TEXTDOMAIN ),
'public' => true,
'exclude_from_search' => false,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => true,
'rewrite' => array( 'with_front' => false, 'slug' => 'products' ),
I have worked out how to change ‘mysite.com/portfolio/example-portfolio’ to ‘mysite.com/products/example-portfolio’ (on the last line in the example) but I don’t want to stop there!
Since you can categorize the portfolios I would like to take advantage of this in the URLs which are generated.
This is surely possible with not too much work involved, and I would be very grateful if somebody with more php knowledge than myself (which doesn’t take much!) could let me lean on them for a solution
thanks
add
but be sure to remove (not sure why that’s there, it tries hides the slug yet tries to rename it to “products” at the same time?):
So it looks like this:
just make sure the register_post_type closes out correctly, the code you posted ends in the middle of the array. i closed it for you but i’m not sure if you left anything out. some examples here: http://codex.wordpress.org/Function_Reference/register_post_type
Could you not just do this with Permalink?
http://codex.wordpress.org/Using_Permalinks