Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
So what do you want the URLs to look like? –  Miha Rekar Oct 7 '12 at 9:31
3  
this would be much simpler if you just created a custom "photo" post type and separated them from normal posts. –  Milo Oct 7 '12 at 14:59
    
@MihaRekar Look at my edit. –  Bram Vanroy Oct 8 '12 at 7:32
    
@Milo I tried custom post types, but this didn't seem to work well with the parent theme I use. But, let's say I would use a custom type: can you give a specific answer on this post which states how to create a custom post type and how to change the urls accordingly? –  Bram Vanroy Oct 8 '12 at 7:36
2  
Look into WordPress Custom Post Type Code Generator –  Miha Rekar Oct 8 '12 at 10:22

1 Answer 1

up vote 0 down vote accepted

I solved it myself (with you guys' help): It was easy as anything:

'rewrite' => array(
            'slug' => 'videos',
            'with_front' => false
        ),
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.