1

How archive php file should be named?

Url:

mypage.com/gallerycategory/sport/

gallerycategory - slug of custom taxonomy of custom post type (name of custom taxonomy is gallery_categories with slug gallerycategory)

'sport' - one of terms (categories) of gallerycategory .

Currently this page hits archive.php file, but I need to create specific file for this pattern ('gallerycategory'/'customtaxonomyterm').

Here is how I register:

 $labels = array(
        'name' => __('VmGallery', THEME_TEXT_DOMAIN, THEME_TEXT_DOMAIN),
        'singular_name' => __('VmGallery', THEME_TEXT_DOMAIN),
        ...
    );
    $supports = array('title', 'editor', 'thumbnail', 'excerpt' ...);
    $args = array(
        'labels' => $labels,
        'description' => 'VM galleries',
        'public' => true,
        'supports' => $supports,
        'taxonomies' => array('gallery_categories', 'post_tag'),            
        'has_archive' => 'gallery'
    );

    register_post_type('vmgallery', $args);


register_taxonomy(
    'gallery_categories', 'VmGallery', array(
        'hierarchical' => true,
        'label' => __('Categories', THEME_TEXT_DOMAIN),
        'query_var' => true,            
        'rewrite' => array(
            'slug' => 'gallerycategory',
            'with_front' => false
        ),
    )
3

If you need the archive index for a custom taxonomy, you would use taxonomy-{taxonomy}.php template file. So, if you've created a custom taxonomy, gallery-exhibitions, the archive index for this taxonomy would use the taxonomy-gallery-exhibitions.php template file.

If you need the archive index for terms for your custom taxonomy, you would use taxonomy-{taxonomy}-{term}.php template file. So, if you've got a term, future-exhibitions, for your custom taxonomy, the archive index for this term would be taxonomy-gallery-exhibitions-future-exhibitions.php.

(Note: I'm not sure how hyphenated taxonomy and term slugs will impact the template hierarchy; it shouldn't, but if you run into problems, you might try using single-word terms for taxonomy and term.)

  • Change the rewrite slug of register texonomy and then create the page of this name it will working.. – Piyush Dhanotiya Mar 2 '16 at 10:36

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.