【问题标题】:Landing in 404 Page on Navigating to Custom Taxonomy Archive登陆 404 页面导航到自定义分类档案
【发布时间】:2021-05-25 18:24:08
【问题描述】:

能否请您看一下这篇文章并告诉我如何正确导航到分类 URL?拥有一个名为 movie 的 CPT 和一个名为 genre 的分类法,我如何导航到 taxonomy.phptaxonomy-genre.php 的存档中

<?php 
    flush_rewrite_rules( false );
function custom_post_type_movie() {
    $labels = array(
        'name'                  => 'movies',
        'singular_name'         => 'movie',
        'menu_name'             => 'Movies',
        'name_admin_bar'        => 'Post Type',
        'archives'              => 'Item Archives',
        'attributes'            => 'Item Attributes',
        'parent_item_colon'     => 'Parent Item:',
        'all_items'             => 'All Items',
        'add_new_item'          => 'Add New Item',
        'add_new'               => 'Add New',
        'new_item'              => 'New Item',
        'edit_item'             => 'Edit Item',
        'update_item'           => 'Update Item',
        'view_item'             => 'View Item',
        'view_items'            => 'View Items',
        'search_items'          => 'Search Item',
        'not_found'             => 'Not found',
        'not_found_in_trash'    => 'Not found in Trash',
        'featured_image'        => 'Featured Image',
        'set_featured_image'    => 'Set featured image',
        'remove_featured_image' => 'Remove featured image',
        'use_featured_image'    => 'Use as featured image',
        'insert_into_item'      => 'Insert into item',
        'uploaded_to_this_item' => 'Uploaded to this item',
        'items_list'            => 'Items list',
        'items_list_navigation' => 'Items list navigation',
        'filter_items_list'     => 'Filter items list',
    );
    $args = array(
        'label'                 => 'movie',
        'description'           => 'Post Type Description',
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor' ),
        'taxonomies'            => array( 'genre' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 2,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( 'movie', $args );

}
add_action( 'init', 'custom_post_type_movie', 0 );


function genre() {

    $labels = array(
        'name'                       => 'Movie Genres',
        'singular_name'              => 'Taxonomy',
        'menu_name'                  => 'Genre',
        'all_items'                  => 'All Items',
        'parent_item'                => 'Parent Item',
        'parent_item_colon'          => 'Parent Item:',
        'new_item_name'              => 'New Item Name',
        'add_new_item'               => 'Add New Genre',
        'edit_item'                  => 'Edit Item',
        'update_item'                => 'Update Item',
        'view_item'                  => 'View Item',
        'separate_items_with_commas' => 'Separate items with commas',
        'add_or_remove_items'        => 'Add or remove items',
        'choose_from_most_used'      => 'Choose from the most used',
        'popular_items'              => 'Popular Items',
        'search_items'               => 'Search Items',
        'not_found'                  => 'Not Found',
        'no_terms'                   => 'No items',
        'items_list'                 => 'Items list',
        'items_list_navigation'      => 'Items list navigation',
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'genre', array( 'movie' ), $args );

}
add_action( 'init', 'genre', 0 );
?>

在我的主题目录中,我有 3 个分类文件,例如

在他们每个人中我都有类似的代码

<?php
get_header();
?>

<main id="main" class="site-main" role="main">
    <?php 
    if ( have_posts() ) : 
        while ( have_posts() ) : the_post(); 
            // Display post content
            the_title();
        endwhile; 
    endif; 
    ?>
</main>

<?php
get_footer();

http://wpdev/genrehttp://wpdev/movie/genre 我登陆404 页面

【问题讨论】:

  • 您是否尝试过重置您的永久链接设置。
  • 是的,Alex 我试过了,但还是不行。正如我之前提到的,http://wpdev/genre/action/ 列出了相关的 CPT,但http://wpdev/genre/ 仍然显示404 页面

标签: wordpress wordpress-theming taxonomy custom-taxonomy


【解决方案1】:

taxonomy-genre.php中执行如下代码

<?php
get_header();
?>

<main id="main" class="site-main" role="main">
    <?php
        the_archive_title( '<h1 class="page-title">', '</h1>' );
    ?>
</main>

<?php
get_footer();

你的代码在这里工作,所以我认为你应该保存永久链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 2015-04-11
    • 2016-11-11
    • 1970-01-01
    相关资源
    最近更新 更多