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.

Is it possible to not use the loop for the base URL of a custom post type.

So for instance if my custom post type is 'directory'.

I don't want http://www.mysite.com/directory/ to land at the loop page, I want to make a custom page template that will serve a customised layout for proceeding into areas of the custom post type, based on taxonomies etc.

However for a single post I do still want to keep the custom post type name in the URL.

So - http://www.mysite.com/directory/listing_type/listing_locale/postname/

If anyone could help with this, i'd much appreciate it.

Edit - post creation snippet

register_post_type( 'directory',
        array(
            'labels' => array(
                'name' => __( 'Directory Listing' ),
                'singular_name' => __( 'Directorys' ),
                'add_new' => __( 'Add directory listing' ),
                'add_new_item' => __( 'Add directory listing' ),
                'edit' => __( 'Edit' ),
                'edit_item' => __( 'Edit Directory' ),
                'new_item' => __( 'Add a directory listing' ),
                'view' => __( 'View Directory' ),
                'view_item' => __( 'View Directory' ),
                'search_items' => __( 'Search Directorys' ),
                'not_found' => __( 'No Directory found' ),
                'not_found_in_trash' => __( 'No Directory found in Trash' ),
                'parent' => __( 'Parent Directorys' ),
            ),
            'public' => true,
            'query_var' => true,
            'menu_position' => 35,
            'show_ui' => true,
            'supports' => array('title','thumbnail','page-attributes','revisions'),
            'publicly_queryable' => true,
            'exclude_from_search' => true,
            'hierarchical' => true
        )
    );
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

You need the has_archive option set to true when registering your custom post type with the register_post_type function, in order for the archive-{posttype}.php file to work.

share|improve this answer
add comment

Try to create page/file called archive-{posttype}.php. It's post type name NOT post type slug.

function create_post_type() {
    register_post_type( 'acme_product',
        array(
            'labels' => array(
                'name' => __( 'Products' ),
                'singular_name' => __( 'Product' )
            ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'product-slug'),
        )
    );
}

Check also template Hierarchy.

share|improve this answer
    
I created page-directory.php but it still loads the loop instead. –  David Aug 24 '12 at 11:34
    
What I want to do is make the /directory/ not load the loop and infact load a template in the least hacky way possible. –  David Aug 24 '12 at 12:06
    
Ok, I update my answer and check. It works. –  Mateusz Aug 24 '12 at 13:29
    
For me this still just loads the regular loop when accessing the url somesite.com/directory even after adding a archive-directory.php file. –  David Aug 24 '12 at 13:34
    
Viewing template hiearchy would also seem to suggest that your suggested solutions would not work. –  David Aug 24 '12 at 14:01
show 2 more comments

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.