将静态页面重定向到home.php的问题

时间:2021-06-18 作者:Bertrand B

我的WordPress网站主题有一些问题。在创建的某个点。主题使用的php文件出错了。基本上,如果我在wordpress back office的设置中使用帖子标题创建永久链接,我的所有静态页面似乎都会重定向到home.php. 我尝试了几种方法:重新生成永久链接,更改现有页面的段塞,创建新页面。这些都有相同的结果:访问静态页面仍然会将我重定向到home.php...

但是,当我改变永久链接的类型时,例如使用简单的永久链接(url中有帖子的id),事情就会得到解决。如果我保留;职位名称“;permalink格式,但在我的静态页面中添加了父页面。

我开始调试,并意识到问题似乎来自我为某些自定义帖子类型创建的自定义分类法。实际上,如果我注释掉我用来创建3个自定义分类法的函数,以及add_action 要加载上述分类法,它工作得很好。我相信我可能忘记了什么(可能在重写属性中?)但我在技能上还有一些差距需要填补。

下面是我的自定义帖子类型和分类的声明,如果你看到一些奇怪的东西,一定要让我知道。。。


function wpm_custom_post_type() {

    $labels = array(
        \'name\'                => _x( \'Etudiants\', \'Post Type General Name\'),
        \'singular_name\'       => _x( \'Etudiant\', \'Post Type Singular Name\'),
        \'menu_name\'           => __( \'Les étudiants\'),
        \'all_items\'           => __( \'Les étudiants\'),
        \'view_item\'           => __( \'Voir les étudiants\'),
        \'add_new_item\'        => __( \'Ajouter étudiant\'),
        \'add_new\'             => __( \'Ajouter\'),
        \'edit_item\'           => __( \'Modifier étudiant\'),
        \'update_item\'         => __( \'Mettre à jour étudiant\'),
        \'search_items\'        => __( \'Chercher étudiant\'),
        \'not_found\'           => __( \'Pas de résultat\'),
        \'not_found_in_trash\'  => __( \'Pas de résultat\'),
    );

    $args = array(
        \'label\'               => __( \'Etudiants\'),
        \'description\'         => __( "Les étudiants de l\'école"),
        \'labels\'              => $labels,
        \'menu_icon\'           => \'dashicons-welcome-learn-more\',
        \'supports\'            => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'revisions\', \'custom-fields\', ),
        \'show_in_rest\' => true,
        \'hierarchical\'        => false,
        \'public\'              => true,
        \'has_archive\'         => true,
        \'rewrite\'             => array( \'slug\' => \'students\'),

    );

    register_post_type( \'student\', $args );


    $labels = array(
        \'name\'                => _x( \'Modules\', \'Post Type General Name\'),
        \'singular_name\'       => _x( \'Module\', \'Post Type Singular Name\'),
        \'menu_name\'           => __( \'Modules\'),
        \'all_items\'           => __( \'La formation\'),
        \'view_item\'           => __( \'Voir les modules\'),
        \'add_new_item\'        => __( \'Ajouter un module\'),
        \'add_new\'             => __( \'Ajouter\'),
        \'edit_item\'           => __( \'Modifier le module\'),
        \'update_item\'         => __( \'Mettre à jour le module\'),
        \'search_items\'        => __( \'Chercher modules\'),
        \'not_found\'           => __( \'Pas de résultat\'),
        \'not_found_in_trash\'  => __( \'Pas de résultat\'),
    );

    $args = array(
        \'label\'               => __( \'Modules\'),
        \'description\'         => __( "Les modules de formation"),
        \'labels\'              => $labels,
        \'menu_icon\'           => \'dashicons-desktop\',
        \'supports\'            => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'revisions\', \'custom-fields\', ),
        \'show_in_rest\' => true,
        \'hierarchical\'        => false,
        \'public\'              => true,
        \'has_archive\'         => true,
        \'rewrite\'             => array( \'slug\' => \'modules\'),


    );

    register_post_type( \'module\', $args );
}





function wpm_add_taxonomies() {

    $labels_domain = array(
        \'name\'                       => _x( \'Filières\', \'taxonomy general name\'),
        \'singular_name\'              => _x( \'Filière\', \'taxonomy singular name\'),
        \'search_items\'               => __( \'Rerchercher filières\'),
        \'popular_items\'              => __( \'Filières populaires\'),
        \'all_items\'                  => __( \'Toutes les filières\'),
        \'edit_item\'                  => __( \'Modifier filière\'),
        \'update_item\'                => __( \'Mettre à jour la filière\'),
        \'add_new_item\'               => __( \'Ajouter une filière\'),
        \'new_item_name\'              => __( \'Nom de la filière\'),
        \'separate_items_with_commas\' => __( \'Ajouter une virgule entre chaque filière\'),
        \'add_or_remove_items\'        => __( \'Ajouter ou supprimer une filière\'),
        \'choose_from_most_used\'      => __( \'Choisir parmi les plus utilisées\'),
        \'not_found\'                  => __( \'Aucune filière trouvée\'),
        \'menu_name\'                  => __( \'Filières\'),
    );

    $args_domain = array(
        \'hierarchical\'          => false,
        \'labels\'                => $labels_domain,
        \'show_ui\'               => true,
        \'show_in_rest\'          => true,
        \'show_admin_column\'     => true,
        \'update_count_callback\' => \'_update_post_term_count\',
        \'query_var\'             => true,
        \'rewrite\'               => array( \'slug\' => \'domains\' ),
    );

    register_taxonomy( \'domain\', \'student\', $args_domain );

    $labels_year = array(
        \'name\'                       => _x( \'Promotions\', \'taxonomy general name\'),
        \'singular_name\'              => _x( \'Promotion\', \'taxonomy singular name\'),
        \'search_items\'               => __( \'Rerchercher promotions\'),
        \'popular_items\'              => __( \'Promotions populaires\'),
        \'all_items\'                  => __( \'Toutes les promotions\'),
        \'edit_item\'                  => __( \'Modifier promotion\'),
        \'update_item\'                => __( \'Mettre à jour la promotion\'),
        \'add_new_item\'               => __( \'Ajouter une promotion\'),
        \'new_item_name\'              => __( \'Nom de la promotion\'),
        \'separate_items_with_commas\' => __( \'Ajouter une virgule entre chaque promotion\'),
        \'add_or_remove_items\'        => __( \'Ajouter ou supprimer une promotion\'),
        \'choose_from_most_used\'      => __( \'Choisir parmi les plus utilisées\'),
        \'not_found\'                  => __( \'Aucune promotion trouvée\'),
        \'menu_name\'                  => __( \'Promotions\'),
    );

    $args_year = array(
        \'hierarchical\'          => false,
        \'labels\'                => $labels_year,
        \'show_ui\'               => true,
        \'show_in_rest\'          => true,
        \'show_admin_column\'     => true,
        \'update_count_callback\' => \'_update_post_term_count\',
        \'query_var\'             => true,
        \'rewrite\'               => array( \'slug\' => \'year\' ),
    );

    register_taxonomy( \'year\', \'student\', $args_year );

    $labels_training = array(
        \'name\'                       => _x( \'Formations\', \'taxonomy general name\'),
        \'singular_name\'              => _x( \'Formation\', \'taxonomy singular name\'),
        \'search_items\'               => __( \'Rerchercher formations\'),
        \'popular_items\'              => __( \'Formations populaires\'),
        \'all_items\'                  => __( \'Toutes les formations\'),
        \'edit_item\'                  => __( \'Modifier formation\'),
        \'update_item\'                => __( \'Mettre à jour la formation\'),
        \'add_new_item\'               => __( \'Ajouter une formation\'),
        \'new_item_name\'              => __( \'Nom de la formation\'),
        \'separate_items_with_commas\' => __( \'Ajouter une virgule entre chaque formation\'),
        \'add_or_remove_items\'        => __( \'Ajouter ou supprimer une formation\'),
        \'choose_from_most_used\'      => __( \'Choisir parmi les plus utilisées\'),
        \'not_found\'                  => __( \'Aucune formation trouvée\'),
        \'menu_name\'                  => __( \'Formations\'),
    );

    $args_training = array(
        \'hierarchical\'          => false,
        \'labels\'                => $labels_training,
        \'show_ui\'               => true,
        \'show_in_rest\'          => true,
        \'show_admin_column\'     => true,
        \'update_count_callback\' => \'_update_post_term_count\',
        \'query_var\'             => true,
        \'rewrite\'               => array( \'slug\' => \'training\' ),
    );

    register_taxonomy( \'training\', \'module\', $args_training );
}
add_action( \'init\', \'wpm_add_taxonomies\', 0 );
add_action( \'init\', \'wpm_custom_post_type\', 0 );

1 个回复
SO网友:Bertrand B

问题的答案是:我将我的一个自定义分类命名为year, 这可能会在查询静态页面时产生一些问题。。。应该早点注意到,但嘿,至少它已经修好了!