我一直在嘗試幾天來創建一個自定義帖子類型與類別。到目前爲止,我有這個工作,我可以很容易地添加內容,並將其分配給一個類別。我的代碼如下。自定義帖子類型和類別
我不明白,似乎無法正常工作是創建一個存檔頁面來顯示類別的帖子。
例如:我的帖子類型被稱爲廣告。我的類別被稱爲攝影師。
頁面是否可以動態調出您正在使用的類別並顯示屬於該類別的所有自定義帖子?
function my_custom_post_advert() {
$labels = array(
'name' => _x('Adverts', 'post type general name'),
'singular_name' => _x('Advert', 'post type singular name'),
'add_new' => _x('Add New', 'advert'),
'add_new_item' => __('Add New Advert'),
'edit_item' => __('Edit Advert'),
'new_item' => __('New Advert'),
'all_items' => __('All Adverts'),
'view_item' => __('View Advert'),
'search_items' => __('Search Adverts'),
'not_found' => __('No adverts found'),
'not_found_in_trash' => __('No adverts found in the Trash'),
'parent_item_colon' => '',
'menu_name' => 'Adverts'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our adverts and advert specific data',
'public' => true,
'menu_position' => 5,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'category'),
'has_archive' => true,
);
register_post_type('advert', $args);
}
add_action('init', 'my_custom_post_advert');
function my_taxonomies_advert() {
$labels = array(
'name' => _x('Advert Categories', 'taxonomy general name'),
'singular_name' => _x('Advert Category', 'taxonomy singular name'),
'search_items' => __('Search Advert Categories'),
'all_items' => __('All Advert Categories'),
'parent_item' => __('Parent Advert Category'),
'parent_item_colon' => __('Parent Advert Category:'),
'edit_item' => __('Edit Advert Category'),
'update_item' => __('Update Advert Category'),
'add_new_item' => __('Add New Advert Category'),
'new_item_name' => __('New Advert Category'),
'menu_name' => __('Advert Categories'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
);
register_taxonomy('advert_category', 'advert', $args);
}
add_action('init', 'my_taxonomies_advert', 0);
爲什麼不是這樣的正確答案?我錯過了什麼嗎?我不知道這個頁面上的答案有一半是在說什麼! –