问题描述
我认为这个问题已经得到了很多回答,但是尽管有所有主题,我仍然找不到有效答案:
在这里创建我的自定义帖子类型“ actuality”和与之相关的分类法,名称为“ actuality_type:
<?PHP
function create_actuality_taxonomy() {
$labels = array(
'name' => _x( 'Type d\'actualité','taxonomy general name','textdomain' ),'singular_name' => _x( 'Type d\'actualité','taxonomy singular name','search_items' => __( 'Chercher un type','all_items' => __( 'Tout les types','edit_item' => __( 'Editer le type','update_item' => __( 'Mettre à jour le type','add_new_item' => __( 'Ajouter un nouveau type','new_item_name' => __( 'Nom du nouveau type','menu_name' => __( 'Type d\'actualité',);
$args = array(
'hierarchical' => true,'labels' => $labels,'show_ui' => true,'show_admin_column' => false,'query_var' => true,'rewrite' => array(
'slug' => 'actuality',// This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
),'show_in_rest' => true,'show_in_quick_edit'=> false,'public' => true,'Meta_Box_cb' => false,'show_in_nav_menus' => false,'has_archive' => true
);
//first name of the taxonomy,second post_type name
register_taxonomy( 'actuality_type','actuality',$args );
}
function create_actuality_custom_post_type() {
$labels = array(
'name' => _x( 'Actualités','Post Type General Name'),'singular_name' => _x( 'Actualité','Post Type Singular Name'),'menu_name' => __( 'Ajouter une Actu'),'all_items' => __( 'Toutes les Actualités'),'view_item' => __( 'Voir les actualités'),'add_new_item' => __( 'Ajouter une nouvelle Actualité'),'add_new' => __( 'Ajouter'),'edit_item' => __( 'Editer l\'Actualité'),'update_item' => __( 'Modifier l\'Actualité'),'search_items' => __( 'Rechercher une Actualité'),'not_found' => __( 'Non trouvée'),'not_found_in_trash' => __( 'Non trouvée dans la corbeille'),);
$args = array(
'label' => __('actuality'),'description' => __( 'Toute l\'actualité'),'menu_icon' => 'dashicons-admin-site','labels' => $labels,'supports' => array( 'title','editor','excerpt','author','thumbnail','revisions','custom-fields' ),'show_in_rest' => true,'hierarchical' => false,'public' => true,'publicly_queryable' => true,'menu_position' => 4,'has_archive' => 'actuality','rewrite' => array(
'slug' => 'actuality/%actuality_type%','with_front' => false
),'capability_type' => 'post',);
register_post_type( 'actuality',$args );
}
现在,在我的function.PHP文件中,这就是我实现这些的方式:
/*
* Add the menu "Create News" and Custom post typr on the admin page
*/
add_action('init','create_actuality_custom_post_type',0);
/*
* Register new taxonomy for Actualities: News,Event and Salon
*/
add_action('init','create_actuality_taxonomy',0);
/*
* Change permalink for actuality taxonomy
*/
function filter_post_type_link_for_actuality($link,$post) {
if ( $post->post_type !== 'actuality' ) {
return $link;
}
if ( $cats = get_the_terms($post->ID,'actuality_type') ) {
$link = str_replace('%actuality_type%',array_pop($cats)->slug,$link);
}
return $link;
}
add_filter('post_type_link','filter_post_type_link_for_actuality',10,2);
菜单显示在我的管理页面上,我可以创建一些“ actuality_type”,例如“沙龙”。
现在,如果我以“永远的沙龙”为标题创建一个新的“事实”,并且在沙龙上设置了“ actuality_type”,则永久链接为:http:// localhost / mywordpress / actuality / salons / salons-永远/
但是我在此链接上有一个404,但我不知道为什么。我凭经验创建了很多类似的文件
- actuality-salons.PHP
- actuality_type-salons.PHP
- archive-actuality-salons.PHP
- archive-actuality_type-salons.PHP
- page-salons.PHP
- page-actuality-salons.PHP
- page-actuality_type-salons.PHP
- single-actuality-salons.PHP
- single-actuality_type-salons.PHP
- taxonomy-actuality-salons.PHP
- taxonomy-actuality_type-salons.PHP
但是没有一个。
我已经尝试使用flush_rewrite_rules(false);或重新加载设置上的永久链接。
非常感谢大家
祝你有美好的一天
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)