向自定义帖子添加类别。例如:
add_action( \'init\', \'create_gallery_taxonomies\', 0 );
function create_gallery_taxonomies() {
$labels = array(
\'name\' => _x( \'B&A Categories\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'B&A\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search B&A Categories\' ),
\'all_items\' => __( \'All B&A Categories\' ),
\'parent_item\' => __( \'Parent B&A Category\' ),
\'parent_item_colon\' => __( \'Parent B&A Category:\' ),
\'edit_item\' => __( \'Edit B&A Category\' ),
\'update_item\' => __( \'Update B&A Category\' ),
\'add_new_item\' => __( \'Add New B&A Category\' ),
\'new_item_name\' => __( \'New B&A Category Name\' ),
\'menu_name\' => __( \'B&A Categories\' ),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'gallery-categories\' ),
);
register_taxonomy( \'gallery-categories\', array( \'gallery_post\' ), $args );
}
查看最后一行的“gallery\\u post”,这将是您自定义的帖子类型。
然后可以将参数添加到url,并仅显示类别中的参数
$gallery_slug = $_GET[\'parameter\'];
$gallery_menu = get_terms(\'gallery-categories\', \'hide_empty=1\');
foreach($gallery_menu as $item) {
if( $item->slug == $gallery_slug ) {
$current_cat = $item;
}
}
if( !$current_cat )
$current_cat = get_term(81, \'gallery-categories\'); // DEFAULT CATEGORY TO SHOW
$args = array(
\'post_type\' => \'gallery_post\',
\'taxonomy\' => $current_cat->taxonomy,
\'term\' => $current_cat->slug,
\'posts_per_page\' => -1,
\'nopaging\' => true,
);
$query = new WP_Query( $args );
在单个模板上,您必须检查帖子必须显示哪些类别的所需信息。