0
編輯:現在我發現這是Hybrid Core,顯然模板層次結構不同。儘管如此,我仍然沒有解決我的問題。Wordpress自定義帖子類型 - 發佈屬性:模板。模板顯示並保存在後端,但正在呈現默認主題文件
除了標題。我的想法是,如果我能夠在後端選擇一個模板,它應該尊重這個選擇。儘管如此,它並沒有改變。我已經測試了另一個模板文件來代替默認設置,它可以工作。
這是添加我的自定義帖子類型的功能。這工作得很好。
add_action('init', 'register_cpt_location');
function register_cpt_location() {
$labels = array(
'name' => _x('Locations', 'info_locaiton'),
'singular_name' => _x('Location', 'info_location')
);
$args = array(
'labels' => $labels,
'description' => 'Custom Post Type for Location',
'hierarchical' => true,
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields', 'revisions', 'page-attributes'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 6,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => array(
'slug' => 'location',
'with_front' => false,
'feeds' => true,
'pages' => true
),
'menu_icon' => 'dashicons-location',
'capability_type' => 'post'
);
register_post_type('info_location', $args);
}
當我爲自定義帖子類型添加模板(僅在幾篇文章中使用)時,metabox顯示出我的新模板。但是,實時頁面仍然使用自定義帖子類型的默認模板。
默認模板是「info_location.php」。
這是我的模板文件「info_location-fm.php」的頭信息。
/*
* Template Name: Location-fm
* Template Post Type: info_location
*/
顯示下拉的
選擇並保存新模板,仍然無法正常工作(見下文)的模板(下)
謝謝您的回答,以及錯字修復:)看來,原來開發使用的「混合動力核心」開發這個網站,並在該框架食堂用的模板。我需要閱讀它的文檔。我在嘗試之前詢問過「single-info_location.php」,但仍使用「info_location.php」。 –