在网站的根目录中添加Wordpress。希望以页面的URL结构为例。com/{page slug},并以帖子为例。com/academy/{post-slug}。我将永久链接设置为自定义,结构为/academy/%postname%。
这很有效。但是,我有一个自定义的post类型,称为definitions。我想以定义URL结构为例。com/glossary/{定义slug}。目前与上述设置,我得到了一个例子的URL。com/academy/definition/{definition slug}
有没有办法从post permalink设置中排除自定义帖子类型?
以下是我的自定义帖子定义:
function create_posttypes() {
$labels1 = array(
\'name\' => __( \'Definitions\' ),
\'singular_name\' => __( \'Definition\' ),
\'all_items\' => __( \'All Definitions\' ),
\'view_item\' => __( \'View Definition\' ),
\'add_new_item\' => __( \'Add New Definition\' ),
\'edit_item\' => __( \'Edit Definition\' ),
\'update_item\' => __( \'Update Definition\' ),
\'search_items\' => __( \'Search Definitions\' ),
\'not_found\' => __( \'Not Found\' ),
\'not_found_in_trash\' => __( \'Not Found in Trash\' ),
);
$args1 = array(
\'label\' => \'Definitions\',
\'description\' => \'Definitions received\',
\'labels\' => $labels1,
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\', \'definitions\'),
\'hierarchical\' => false,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'can_export\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'page\',
\'supports\' => array(\'title\',\'thumbnail\', \'revisions\', \'page-attributes\')
);
register_post_type( \'definitions\', $args1 );
}
最合适的回答,由SO网友:Dave Romsey 整理而成
您可以使用rewrite
参数以禁用URL的前部(/academy/
在您的情况下),用于自定义帖子类型。
function create_posttypes() {
$labels1 = array(
\'name\' => __( \'Definitions\' ),
\'singular_name\' => __( \'Definition\' ),
\'all_items\' => __( \'All Definitions\' ),
\'view_item\' => __( \'View Definition\' ),
\'add_new_item\' => __( \'Add New Definition\' ),
\'edit_item\' => __( \'Edit Definition\' ),
\'update_item\' => __( \'Update Definition\' ),
\'search_items\' => __( \'Search Definitions\' ),
\'not_found\' => __( \'Not Found\' ),
\'not_found_in_trash\' => __( \'Not Found in Trash\' ),
);
$args1 = array(
\'label\' => \'Definitions\',
\'description\' => \'Definitions received\',
\'labels\' => $labels1,
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(
\'slug\' => \'glossary\',
\'with_front\' => false,
),
\'hierarchical\' => false,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'can_export\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'page\',
\'supports\' => array(\'title\',\'thumbnail\', \'revisions\', \'page-attributes\')
);
register_post_type( \'definitions\', $args1 );
}