简体   繁体   中英

Wordpress taxonomy template not working

I created a custom wordpress taxonomy, which relates to the post type "portfolio". I created a taxonomy.php template file. But when I am trying to view posts in this taxonomy, a blank page opens. The log is empty. How do I fix it?

The portfolio post type was created with the following code:

add_action( 'init', 'create_post_type' );

function create_post_type() {
    register_post_type( 'portfolio',
            array(
                    'labels' => array(
                            'name' => __( 'Портфолио' ),
                            'singular_name' => __( 'Работа' ),
                            'add_new' => 'Добавить работу',
                            'add_new_item' => 'Добавить новую работу',
                            'edit_item' => 'Редактировать работу'
                    ),
                    'public' => true,
                    'supports' => array('title', 'editor'),
                    'exclude_from_search' => false,
                    'taxonomies' => array('portfolio_categories')
            )
    );
} 

And the portfolio_categories taxonomy was created with the following code:

add_action( 'init', 'create_portfolio_taxonomies', 0 );
function create_portfolio_taxonomies(){
    $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' => __( 'Категории работ' )
    );

register_taxonomy('portfolio_categories', array('portfolio'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => 'portfolio_categories',
        'rewrite' => array( 'slug' => 'portfolio_categories' )
));
}

you have to create template in your theme like

taxonomy-{yourtaxonomy}-{yourslug}.php

OR

taxonomy-{yourtaxonomy}.php

if not works for you than Go to Settings -> Permalinks And under Common Settings, let's use Post name. Then click 'Save Changes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM