我已经创建了一个自定义帖子类型和分类法,当我单击分类法链接时,它返回404错误,
这就是我创建自定义帖子类型和分类法的方式。
function create_post_type_press()
{
$labels = array(\'name\' => __( \'News\', \'example\' ),
\'singular_name\' => __( \'News\', \'example\' ),
// \'add_new\' => __( \'Add New Article\', \'example\' ),
\'add_new_item\' => __( \'Add News\', \'example\' ),
\'edit_item\' => __( \'Edit News\', \'example\' ),
\'new_item\' => __( \'New News\', \'example\' ),
\'view_item\' => __( \'View PNews\', \'example\' ),
\'search_items\' => __( \'Search News\', \'example\' ),
\'not_found\' => __( \'No News found\', \'example\' ),
\'not_found_in_trash\' => __( \'No News found in Trash\', \'example\' ),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'News\');
$args = array( \'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'show_in_nav_menus\' => true,
\'capability_type\' => \'post\',
\'menu_icon\' => get_template_directory_uri() . \'/image/settings.png\',
\'hierarchical\' => false,
\'menu_position\' => 90,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'revisions\', ),
\'rewrite\' => array( \'slug\' => \'news-topic\', \'with_front\' => false ));
register_post_type( \'news_article\' , $args );
}
add_action( \'init\', \'create_post_type_press\' );
function news_topic() {
register_taxonomy(
\'topic\',
\'news_article\',
array(
\'hierarchical\' => true,
\'label\' => \'Topics\',
\'query_var\' => true,
\'rewrite\' => array(\'slug\' => \'news-topic\')
)
);
}
这是为了获取分类链接。
function get_terms_dropdown($taxonomies, $args){
$myterms = get_terms($taxonomies, $args);
$output ="<select id=\'dynamic_select\'><option selected class=\'drop_down\'>Default</option>";
foreach($myterms as $term){
$root_url = get_bloginfo(\'url\');
$term_taxonomy=$term->taxonomy;
$term_slug=$term->slug;
$term_name =$term->name;
$link = $term_slug;
$output .="<option><a href=\'".$term_link."\'>".$term_name."</a></option>";
}
$output .="</select>";
return $output;
}
$taxonomies = array(\'topic\');
$args = array(\'orderby\'=>\'count\',\'hide_empty\'=>true);
echo get_terms_dropdown($taxonomies, $args);
当我点击链接时,它会转到
http://domain/news/taxonomy