0

I am trying to create archives page for my custom post types but it is going to a default archive page not the archive page which i have created for archives

Here is my code for custom post type

    // Register Custom Post Type
function gallery_post_type() {

    $labels = array(
        'name' => _x('Gallery images', 'Post Type General Name', 'horst'),
        'singular_name' => _x('Gallery image', 'Post Type Singular Name', 'horst'),
        'menu_name' => __('Photo Gallery', 'horst'),
        'name_admin_bar' => __('Photo Gallery', 'horst'),
        'archives' => __('Item Archives', 'horst'),
        'parent_item_colon' => __('Parent Photo:', 'horst'),
        'all_items' => __('All Photos', 'horst'),
        'add_new_item' => __('Add New Photo', 'horst'),
        'add_new' => __('Add New Gallery image', 'horst'),
        'new_item' => __('New Photo', 'horst'),
        'edit_item' => __('Edit Photo', 'horst'),
        'update_item' => __('Update Photo', 'horst'),
        'view_item' => __('View Photo', 'horst'),
        'search_items' => __('Search Photos', 'horst'),
        'not_found' => __('Not found', 'horst'),
        'not_found_in_trash' => __('Not found in Trash', 'horst'),
        'featured_image' => __('Gallery Image', 'horst'),
        'set_featured_image' => __('Set Gallery image', 'horst'),
        'remove_featured_image' => __('Remove Gallery image', 'horst'),
        'use_featured_image' => __('Use as Gallery image', 'horst'),
        'insert_into_item' => __('Insert into item', 'horst'),
        'uploaded_to_this_item' => __('Uploaded to this Photo', 'horst'),
        'items_list' => __('Photos list', 'horst'),
        'items_list_navigation' => __('Photo list navigation', 'horst'),
        'filter_items_list' => __('Filter Photo list', 'horst'),
    );
    $args = array(
        'label' => __('Gallery image', 'horst'),
        'description' => __('gallery imges for gallery page', 'horst'),
        'labels' => $labels,
        'supports' => array('title', 'thumbnail',),
        'hierarchical' => true,
        'taxonomies' => array(
            'gallery_categories',
        ),
        'rewrite' => array(
            'slug' => 'gallery',
        ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-format-gallery',
        'show_in_admin_bar' => true,
        'show_in_nav_menus' => true,
        'can_export' => true,
        'has_archive' => true,
    );
    register_post_type('gallery', $args);
}

add_action('init', 'gallery_post_type');

and this is my custom taxonomy

// Register Custom Taxonomy
function custom_taxonomy() {

    $labels = array(
        'name'                       => _x( 'Gallery Maps', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Gallery Map', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Gallery Maps', 'text_domain' ),
        'all_items'                  => __( 'All Items', 'text_domain' ),
        'parent_item'                => __( 'Parent Item', 'text_domain' ),
        'parent_item_colon'          => __( 'Parent Item:', 'text_domain' ),
        'new_item_name'              => __( 'New Item Name', 'text_domain' ),
        'add_new_item'               => __( 'Add New Item', 'text_domain' ),
        'edit_item'                  => __( 'Edit Item', 'text_domain' ),
        'update_item'                => __( 'Update Item', 'text_domain' ),
        'view_item'                  => __( 'View Item', 'text_domain' ),
        'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
        'add_or_remove_items'        => __( 'Add or remove items', 'text_domain' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
        'popular_items'              => __( 'Popular Items', 'text_domain' ),
        'search_items'               => __( 'Search Items', 'text_domain' ),
        'not_found'                  => __( 'Not Found', 'text_domain' ),
        'no_terms'                   => __( 'No items', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'gallery_categories', array( 'gallery' ), $args );

}
add_action( 'init', 'custom_taxonomy');

I don't know where am i doing wrong?

  • Are you using archive-posttype.php as the template name? – bravokeyl Apr 25 '16 at 9:57
  • no it was just for reference i am using archive-gallery.php the template name – kamran shahid Apr 25 '16 at 10:49
0

Custom template should be archive-gallery.php instead of archive-posttype.php

It's archive-$posttype.php where $posttype is the custom post type slug.

WordPress first looks for archive-$posttype.php and if it's not available then chooses archive.php

Update

Same for the custom taxonomies also , the flow is:

taxonomy-$taxonomy-$term.php --> taxonomy-$taxonomy.php -->  taxonomy.php --> archive.php

So for gallery_categories custom taxonomy use taxonomy-gallery_categories.php

  • i am using archive-gallery.php already but it is happening to every post-type – kamran shahid Apr 25 '16 at 10:49
  • happening to every post-type? – bravokeyl Apr 25 '16 at 10:50
  • YES its happening to every post-type – kamran shahid Apr 25 '16 at 10:52
  • Sorry i don't get you here , what do you mean by happening to every post type ? do you mean category,tag archives also using same template as archive-gallery – bravokeyl Apr 25 '16 at 10:57
  • i am using only for archive-gallery.php and its taxonomies and those are using default archive.php not my custom template – kamran shahid Apr 25 '16 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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