My main posts are news items (category “news”). Therefore, I used global URI writing in the following format: /year/month/post-name
I also have posts that contain photo albums (category “photo”) but I want these to have another URI structure, namely: /category/post-name
in which category is photos
I’ve been looking over the Internet and I found this link (has category, but I think in category is better) that contains quite some information. I also vaguely remember a hook in functions.php that could do this:
'rewrite' => ...
Unfortunately, for a WordPress Newbee as myself, it’s not enough. I can’t figure out how to do this. Any help? Thanks.
So, if the category is news => /year/month/post-name
e.g. /2012/10/test-post
If other category, such as photos or videos => /category/[sub-category/)post-name
e.g. /photos/(2012/)France
or for videos: /videos/(2011/)concert-u2
EDIT: the comments tell me that it is wiser to use custom post-types.
I have done that. So far I have two custom post types (videos
and photos
). I don’t think that there will be any other. What needs to happen: change the permalink structure of the custom post-types. I want them to be /photos/post-name
and /videos/post-name
. The regular posts should be /year/month/post-name
. I added this to my functions.php
/* Add custom post-type (fotos) (added by Bram Vanroy) */
add_action( 'init', 'register_cpt_foto' );
function register_cpt_foto() {
$labels = array(
'name' => _x( 'fotos', 'foto' ),
'singular_name' => _x( 'foto', 'foto' ),
'add_new' => _x( 'Nieuw fotoalbum', 'foto' ),
'add_new_item' => _x( 'Voeg nieuw fotoalbum toe', 'foto' ),
'edit_item' => _x( 'Bewerk fotoalbum', 'foto' ),
'new_item' => _x( 'Nieuw fotoalbum', 'foto' ),
'view_item' => _x( 'Bekijk fotoalbum', 'foto' ),
'search_items' => _x( 'Zoek in fotoalbums', 'foto' ),
'not_found' => _x( 'Geen fotoalbums gevonden', 'foto' ),
'not_found_in_trash' => _x( 'Geen fotoalbums gevonden in de prullenmand', 'foto' ),
'parent_item_colon' => _x( 'Parent foto:', 'foto' ),
'menu_name' => _x( 'Foto's', 'foto' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Het posttype dat alle foto-albums verzorgt.',
'supports' => array( 'title', 'editor', 'excerpt', 'comments', 'page-attributes' ),
'taxonomies' => array( 'post_tag', 'page-category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'page'
);
register_post_type( 'foto', $args );
}
/* Add custom post-type (videos) (added by Bram Vanroy) */
add_action( 'init', 'register_cpt_video' );
function register_cpt_video() {
$labels = array(
'name' => _x( 'videos', 'video' ),
'singular_name' => _x( 'video', 'video' ),
'add_new' => _x( 'Voeg nieuwe video toe', 'video' ),
'add_new_item' => _x( 'Voeg nieuwe video toe', 'video' ),
'edit_item' => _x( 'Bewerk video', 'video' ),
'new_item' => _x( 'Nieuwe video', 'video' ),
'view_item' => _x( 'Bekijk video', 'video' ),
'search_items' => _x( 'Zoek video's', 'video' ),
'not_found' => _x( 'Geen video's gevonden', 'video' ),
'not_found_in_trash' => _x( 'Geen video's gevonden in de prullenmand', 'video' ),
'parent_item_colon' => _x( 'Parent video:', 'video' ),
'menu_name' => _x( 'Video's', 'video' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Dit posttype wordt gebruikt om filmpjes te publiceren',
'supports' => array( 'title', 'editor', 'excerpt', 'comments', 'page-attributes' ),
'taxonomies' => array( 'post_tag', 'page-category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'page'
);
register_post_type( 'video', $args );
}
And I suppose I need some rewrite rules here, but I don’t know how to!
I solved it myself (with you guys’ help): It was easy as anything: