0

There is a task: Create a new post type (video) with its own post tags and tag page - separate from normal post.

What I've done:

// Create a new post type
register_post_type('video',
    array('labels' => array('name' => 'videos', 'menu_name' => 'Видео', 'singular_name' => 'video', 'add_new' => 'Добавить видео'),
    'public' => true, 'has_archive' => true, 'menu_icon' => 'dashicons-video-alt3', 'supports' => array('title')
));

// Create its own new post tag
function video_tag_taxonomy() {

    $labels = array(
        'name'                       => 'Video Tag',
        'singular_name'              => 'Video Tag',
        'menu_name'                  => 'Метки',
        'all_items'                  => 'All Video Tags',
        'parent_item'                => 'Parent Video Tag',
        'parent_item_colon'          => 'Parent Video Tag:',
        'new_item_name'              => 'New Video Tag',
        'add_new_item'               => 'Добавить новую метку',
        'edit_item'                  => 'Edit Video Tag',
        'update_item'                => 'Update Video Tag',
        'separate_items_with_commas' => 'Метки разделяются запятыми',
        'search_items'               => 'Search Video Tags',
        'add_or_remove_items'        => 'Add or remove Video Tags',
        'choose_from_most_used'      => 'Выбрать из часто используемых меток',
        'not_found'                  => 'Not Found',
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy('video_tag', array( 'video'), $args );

}

add_action( 'init', 'video_tag_taxonomy', 0 );
register_taxonomy_for_object_type( 'video_tag', 'video' );

The problem: if I click one of the new tags, I move on: site.com/video_tag/my_tag_name

But it's an archive page template. And I couldn't create a separate template. I've tried tags-video_tag.php, archive-video.php but nothing happens.

Thanks in advance!

0

You forgot to create taxonomy.php or taxonomy-video_tag.php which should be the templates to use to display your custom taxonomy term archives on. You should have a look at the taxonomy term archive hierarchy

Just remember to flush your permalinks in case

  • 1
    Pieter, thanks! taxonomy-video_tag.php - yes, I forgot about it :) – S. Andrey Mar 1 '16 at 14:50

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.