0

I've registered a custom post type called video, like so:

add_action( 'init', 'create_post_type' );
    function create_post_type() {
    // Videos Post-Type
    $labels = array(
        'name'               => _x( 'الحلقات/الأفلام', 'post type general name', 'qtoon' ),
        'singular_name'      => _x( 'حلقة/فيلم', 'post type singular name', 'qtoon' ),
        'menu_name'          => _x( 'حلقات/الأفلام', 'admin menu', 'qtoon' ),
        'name_admin_bar'     => _x( 'حلقة/فيلم', 'add new on admin bar', 'qtoon' ),
        'add_new'            => _x( 'أضف حلقة/فيلم جديدة', 'حلقة/فيلم', 'qtoon' ),
        'add_new_item'       => __( 'أضف حلقة/فيلم جديدة', 'qtoon' ),
        'new_item'           => __( 'حلقة/فيلم جديدة', 'qtoon' ),
        'edit_item'          => __( 'تعديل الحلقة/فيلم', 'qtoon' ),
        'view_item'          => __( 'عرض الحلقة/فيلم', 'qtoon' ),
        'all_items'          => __( 'جميع الحلقات/الأفلام', 'qtoon' ),
        'search_items'       => __( 'بحث الحلقات/الأفلام', 'qtoon' ),
        'parent_item_colon'  => __( 'المنشور الأب:', 'qtoon' ),
        'not_found'          => __( 'لم يوجد حلقات/الأفلام.', 'qtoon' ),
        'not_found_in_trash' => __( 'لا يوجد حلقات/الأفلام في المهملات.', 'qtoon' )
    );
    $args = array(
        'labels'             => $labels,
        'description'        => __( 'Description.', 'qtoon' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => '', 'with_front' => false),
        'capability_type'    => 'post',
        'has_archive'        => 'video',
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 
                                       'excerpt', 'comments','add_to_slider' ),
        'taxonomies'         => array( 'post_tag' ),
    );
    register_post_type( 'video', $args );
    flush_rewrite_rules();
}

and registered a custom taxonomy called videos to act as a category for the video post type.

This videos taxonomy (just to imagine how I want my site to look like) will contain terms, each term will contain series episodes => the video custom post type.

add_action( 'init', 'create_videos_hierarchical_taxonomy', 0 );
function create_videos_hierarchical_taxonomy() {
    // Add new taxonomy, make it hierarchical like categories
    // First do the translations part for GUI
    $labels = array(
        'name'              => _x( 'مرئيات', 'taxonomy general name' ),
        'singular_name'     => _x( 'مسلسل/فيلم', 'taxonomy singular name' ),
        'search_items'      => __( 'بحث المرئيات' ),
        'all_items'         => __( 'جميع المرئيات' ),
        'parent_item'       => __( 'التصنيف الأب' ),
        'parent_item_colon' => __( 'المسلسل/فيلم الأب:' ),
        'edit_item'         => __( 'تعديل المسلسل/فيلم' ), 
        'update_item'       => __( 'تحديث المسلسل/فيلم' ),
        'add_new_item'      => __( 'أضف مسلسل/فيلم جديد' ),
        'new_item_name'     => __( 'إسم المسلسل/فيلم الجديد' ),
        'menu_name'         => __( 'مرئيات' ),
    );    
    // Now register the taxonomy
    register_taxonomy( 'videos', array( 'video' ), array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'has_archive'       => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'videos', 'with_front' => false ),
    ) );
    flush_rewrite_rules();
}

What I'm trying to do is when I go to http://example.com/videos, it should show a list of terms (TV series).

I created a file named taxonomy.php and another one called taxonomy-videos.php. When I go to http://example.com/videos, it goes to the index.php file and says in the page title, "Page not found".

How to load the taxonomy-videos.php template file when I go to http://example.com/videos?

1 Answer 1

1

A taxonomy archive is a collection of posts, not terms. Even if you loaded the taxonomy template, it wouldn't display anything, since the loop displays posts, not terms. You need to implement the display of terms yourself in a custom page template.

3
  • What do you mean by taxonomy archive ? you mean the files named like (taxonomy-{taxonomy_slugname}.php.) ? So I'll need to create a page manually from the code after registering the taxonomy ?
    – Hazem Taha
    Commented Sep 25, 2015 at 18:57
  • All templates in WordPress display posts, terms in your taxonomy are a collection of posts (archive). There's no concept of a template to display the terms in your archive.
    – Milo
    Commented Sep 25, 2015 at 18:58
  • Thanks for your answer, So I'll need to create a page manually from the code after registering the taxonomy ?
    – Hazem Taha
    Commented Sep 25, 2015 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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