我有一个无插件的自定义帖子类型和分类设置-见下文。我从中获得了CPT的档案,网址为:
/archives/nomination-archive
如果我使用\\u术语($post->ID,\'提名类型\',\'\'),我会在我的每个提名帖子中获得一个很好的链接,指向我的分类术语档案,即:
/archives/nomination-type/best-2013
访问此url会给我一个标题为“2013年最佳”的归档页面,但我无法让它显示任何帖子。。刷新永久链接等
非常感谢您的帮助。。。
add_action( \'init\', \'create_nomination_post_type\' );
function create_nomination_post_type() {
register_post_type( \'nomination\',
array(
\'labels\' => array(
\'name\' => __( \'Nominations\' ),
\'singular_name\' => __( \'Nomination\' ),
\'add_new_item\' => __( \'Add New Nomination\' )
),
\'public\' => true,
\'menu_position\' => 6,
\'exclude_from_search\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'nomination-archive\'),
\'supports\' => array(
\'title\',
\'editor\',
\'author\',
\'thumbnail\',
\'page-attributes\'
),
)
);
}
//
// Add nominatons type taxonomy
//
function add_nomination_type_taxonomies() {
register_taxonomy(\'nomination_type\', \'nomination\', array(
// Hierarchical taxonomy (like categories)
\'hierarchical\' => true,
\'labels\' => array(
\'name\' => _x( \'Nomination Categories\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Nomination Categories\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Nomination Categories\' ),
\'all_items\' => __( \'All Nomination Categories\' ),
\'parent_item\' => __( \'Parent Nomination Categories\' ),
\'parent_item_colon\' => __( \'Parent Nomination Category:\' ),
\'edit_item\' => __( \'Edit Nomination Category\' ),
\'update_item\' => __( \'Update Nomination Category\' ),
\'add_new_item\' => __( \'Add New Nomination Category\' ),
\'new_item_name\' => __( \'New Nomination Category Name\' ),
\'menu_name\' => __( \'Nomination Item Categories\' )
),
//Control the slugs used for this taxonomy
\'rewrite\' => array(
\'slug\' => \'nomination-type\' // This controls the base slug that will display before each term
// \'with_front\' => true, // Don\'t display the category base before "/genres/"
//\'hierarchical\' => false // Allows good urls
)
));
}
add_action( \'init\', \'add_nomination_type_taxonomies\', 0 );