Skip to main content
Pretty up answer
Source Link
t31os
  • 18.7k
  • 3
  • 56
  • 68

YouYes, you'll just need to set the has_archive parameter to true or your chosen slug when registering your custom post type.

So firstly add the has_archive parameter to your post type, here's an example...

add_action( 'init', 'question_10706_init' );

function question_10706_init() {

    register_post_type( 'example', array(
        'labels' => array(
            'name' => __('Examples'),
            'singular_name' => __('Example')
            ),
        'public' => true,
        'show_ui' => true,
        'rewrite' => array(
            'slug' => 'example',
            'with_front' => false
            ),
        //'has_archive' => true // Will use the post type slug, ie. example
        //'has_archive' => 'my-example-archive' // Explicitly setting the archive slug
    ) );

}

The has_archive parameter supports the following settings.

  1. false (default)

NextNo archive

  1. true

The archive url is formulated from the post type slug

www.example.com/example/

  1. 'string'

The archive url is explicitly set to the slug you provided

www.example.com/my-example-archive/

Once you've added the parameter visit the permalink page, doing this will regeneratecause a regeneration of the rewrite rules, accounting for the newcustom post type archive.

NextLastly, create an archive-{$post_type}.php template to handle that archive (it could be a straight copy->paste of your existing archive, make adjustments as necessary).
Noting, that {$post_type} would of course represent the nameslug of your actual post type.

Here's the ticket that introduced the new post type archives.
http://core.trac.wordpress.org/ticket/13818Sourced information:

Mark McWilliams also wrote about this on his blog, WordPress 3.1 Introduces Custom Post Type Archives.

Hope that helps. :)

You just need to set the has_archive parameter to true or your chosen slug when registering the post type.

add_action( 'init', 'question_10706_init' );

function question_10706_init() {

    register_post_type( 'example', array(
        'labels' => array(
            'name' => __('Examples'),
            'singular_name' => __('Example')
            ),
        'public' => true,
        'show_ui' => true,
        'rewrite' => array(
            'slug' => 'example',
            'with_front' => false
            ),
        //'has_archive' => true // Will use the post type slug, ie. example
        //'has_archive' => 'my-example-archive' // Explicitly setting the archive slug
    ) );

}

Next visit the permalink page, doing this will regenerate the rewrite rules, accounting for the new post type archive.

Next create an archive-{$post_type}.php template to handle that archive (it could be a straight copy->paste of your existing archive, make adjustments as necessary). {$post_type} would represent the name of your actual post type.

Here's the ticket that introduced the new post type archives.
http://core.trac.wordpress.org/ticket/13818

Mark McWilliams also wrote about this on his blog, WordPress 3.1 Introduces Custom Post Type Archives.

Hope that helps. :)

Yes, you'll just need to set the has_archive parameter to true or your chosen slug when registering your custom post type.

So firstly add the has_archive parameter to your post type, here's an example...

add_action( 'init', 'question_10706_init' );

function question_10706_init() {

    register_post_type( 'example', array(
        'labels' => array(
            'name' => __('Examples'),
            'singular_name' => __('Example')
            ),
        'public' => true,
        'show_ui' => true,
        'rewrite' => array(
            'slug' => 'example',
            'with_front' => false
            ),
        //'has_archive' => true // Will use the post type slug, ie. example
        //'has_archive' => 'my-example-archive' // Explicitly setting the archive slug
    ) );

}

The has_archive parameter supports the following settings.

  1. false (default)

No archive

  1. true

The archive url is formulated from the post type slug

www.example.com/example/

  1. 'string'

The archive url is explicitly set to the slug you provided

www.example.com/my-example-archive/

Once you've added the parameter visit the permalink page, this will cause a regeneration of the rewrite rules, accounting for the custom post type archive.

Lastly, create an archive-{$post_type}.php template to handle that archive (it could be a straight copy->paste of your existing archive, make adjustments as necessary).
Noting, that {$post_type} would of course represent the slug of your actual post type.

Sourced information:

Hope that helps. :)

Fix typo
Source Link
t31os
  • 18.7k
  • 3
  • 56
  • 68

You just need to set the has_archive parameter to true or your chosen slug when registering the post type.

add_action( 'init', 'question_10706_init' );

function question_10706_init() {

    register_post_type( 'example', array(
        'labels' => array(
            'name' => __('Examples'),
            'singular_name' => __('Example')
            ),
        'public' => true,
        'show_ui' => true,
        'rewrite' => array(
            'slug' => 'example',
            'with_front' => false
            ),
        //'has_archive' => true // Will use the post type slug, ie. example
        //'has_archive' => 'my-example-archive' // Explicitly setting the archive slug
    ) );

}

Next visit the permalink page, doing this will regenerate the rewrite rules, accounting for the new post type archive.

NowNext create an archive-{$post_type}.php template to handle that archive  (it could be a straight copy->paste of your existing archive, make adjustments as necessary).  {$post_type} would represent the name of your actual post type.

Here's the ticket that introduced the new post type archives.
http://core.trac.wordpress.org/ticket/13818

Mark McWillaimsMcWilliams also wrote about this on his blog, WordPress 3.1 Introduces Custom Post Type Archives.

Hope that helps. :)

You just need to set the has_archive parameter to true or your chosen slug when registering the post type.

add_action( 'init', 'question_10706_init' );

function question_10706_init() {

    register_post_type( 'example', array(
        'labels' => array(
            'name' => __('Examples'),
            'singular_name' => __('Example')
            ),
        'public' => true,
        'show_ui' => true,
        'rewrite' => array(
            'slug' => 'example',
            'with_front' => false
            ),
        //'has_archive' => true // Will use the post type slug, ie. example
        //'has_archive' => 'my-example-archive' // Explicitly setting the archive slug
    ) );

}

Next visit the permalink page, this will regenerate the rewrite rules, accounting for the post type archive.

Now create an archive-{$post_type}.php template to handle that archive(it could be a straight copy->paste of your existing archive, make adjustments as necessary).{$post_type} would represent the name of your actual post type.

Here's the ticket that introduced the new post type archives.
http://core.trac.wordpress.org/ticket/13818

Mark McWillaims also wrote about this on his blog, WordPress 3.1 Introduces Custom Post Type Archives.

Hope that helps. :)

You just need to set the has_archive parameter to true or your chosen slug when registering the post type.

add_action( 'init', 'question_10706_init' );

function question_10706_init() {

    register_post_type( 'example', array(
        'labels' => array(
            'name' => __('Examples'),
            'singular_name' => __('Example')
            ),
        'public' => true,
        'show_ui' => true,
        'rewrite' => array(
            'slug' => 'example',
            'with_front' => false
            ),
        //'has_archive' => true // Will use the post type slug, ie. example
        //'has_archive' => 'my-example-archive' // Explicitly setting the archive slug
    ) );

}

Next visit the permalink page, doing this will regenerate the rewrite rules, accounting for the new post type archive.

Next create an archive-{$post_type}.php template to handle that archive  (it could be a straight copy->paste of your existing archive, make adjustments as necessary).  {$post_type} would represent the name of your actual post type.

Here's the ticket that introduced the new post type archives.
http://core.trac.wordpress.org/ticket/13818

Mark McWilliams also wrote about this on his blog, WordPress 3.1 Introduces Custom Post Type Archives.

Hope that helps. :)

Source Link
t31os
  • 18.7k
  • 3
  • 56
  • 68

You just need to set the has_archive parameter to true or your chosen slug when registering the post type.

add_action( 'init', 'question_10706_init' );

function question_10706_init() {

    register_post_type( 'example', array(
        'labels' => array(
            'name' => __('Examples'),
            'singular_name' => __('Example')
            ),
        'public' => true,
        'show_ui' => true,
        'rewrite' => array(
            'slug' => 'example',
            'with_front' => false
            ),
        //'has_archive' => true // Will use the post type slug, ie. example
        //'has_archive' => 'my-example-archive' // Explicitly setting the archive slug
    ) );

}

Next visit the permalink page, this will regenerate the rewrite rules, accounting for the post type archive.

Now create an archive-{$post_type}.php template to handle that archive(it could be a straight copy->paste of your existing archive, make adjustments as necessary).{$post_type} would represent the name of your actual post type.

Here's the ticket that introduced the new post type archives.
http://core.trac.wordpress.org/ticket/13818

Mark McWillaims also wrote about this on his blog, WordPress 3.1 Introduces Custom Post Type Archives.

Hope that helps. :)