Answer the question
In order to leave comments, you need to log in
How to make a general file with the output of records and their categories?
Created a new post type "Works"
// Works Post Type
add_action('init', 'register_post_type_works');
function register_post_type_works(){
register_post_type('works', array(
'label' => null,
'labels' => array(
'name' => 'Работы',
'singular_name' => 'Работа',
'add_new' => 'Добавить',
'add_new_item' => 'Добавление работы',
'edit_item' => 'Редактирование работы',
'new_item' => 'Новая работа',
'view_item' => 'Посмотреть работу',
'search_items' => 'Найти',
'not_found' => 'Не найдено',
'not_found_in_trash' => 'Не найдено в корзине',
'menu_name' => 'Работы',
),
'public' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 9,
'menu_icon' => 'dashicons-pressthis',
'hierarchical' => true,
'supports' => array('title', 'editor', 'thumbnail'),
'taxonomies' => array('works-cat'),
'has_archive' => true,
'rewrite' => true,
'query_var' => true
) );
}
// Works Category
add_action('init', 'register_works_cat');
function register_works_cat(){
register_taxonomy('works-cat', array('works'), array(
'label' => '',
'labels' => array(
'name' => 'Категории',
'singular_name' => 'Категория',
'all_items' => 'Все',
'view_item ' => 'Посмотреть категорию',
'edit_item' => 'Изменить категорию',
'add_new_item' => 'Добавить категорию',
'new_item_name' => 'Новая категория',
'menu_name' => 'Категории',
),
'public' => true,
'hierarchical' => true,
'rewrite' => true,
'show_admin_column' => false
) );
}
Answer the question
In order to leave comments, you need to log in
1. Try to catch in the template_include filter by is_tax()
2. Or create all the same both templates in the hierarchy, and put the "repetitive code" in the template_part.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question