我在 WordPress 中创建了一个名为“Found”的自定义帖子类型。在其中,我创建了两个分类法,“Pets”(命名为 petsfound)和“Electronics”(命名为electronicsfound),这两个分类法都有不同的术语。
如果我在网站上查看使用分类术语的帖子,它们会正确显示,但是,尝试查看该分类的帖子列表会显示 404。因此,会发生以下情况:
https://example.com/found/pets-found/显示 404 页面。
https://example.com/found/pets-found/dog显示宠物发现分类法中的狗列表。
我已经使用 archive.php 和 taxonomy-petsfound.php 进行了测试,但都显示了分类的 404。电子分类法也是如此。
以下是“Found”CPT 和“petsfound”分类法的代码:
function found_custom_post_type() {
$labels = array(
'name' => _x( 'Found Items', 'Post Type General Name', 'lost_and_found' ),
'singular_name' => _x( 'Found', 'Post Type Singular Name', 'lost_and_found' ),
'menu_name' => __( 'Found', 'lost_and_found' ),
'name_admin_bar' => __( 'Found', 'lost_and_found' ),
'archives' => __( 'Item Archives', 'lost_and_found' ),
'parent_item_colon' => __( 'Parent Item:', 'lost_and_found' ),
'all_items' => __( 'All Items', 'lost_and_found' ),
'add_new_item' => __( 'Add New Item', 'lost_and_found' ),
'add_new' => __( 'Add New', 'lost_and_found' ),
'new_item' => __( 'New Item', 'lost_and_found' ),
'edit_item' => __( 'Edit Item', 'lost_and_found' ),
'update_item' => __( 'Update Item', 'lost_and_found' ),
'view_item' => __( 'View Item', 'lost_and_found' ),
'search_items' => __( 'Search Item', 'lost_and_found' ),
'not_found' => __( 'Not found', 'lost_and_found' ),
'not_found_in_trash' => __( 'Not found in Trash', 'lost_and_found' ),
'featured_image' => __( 'Featured Image', 'lost_and_found' ),
'set_featured_image' => __( 'Set featured image', 'lost_and_found' ),
'remove_featured_image' => __( 'Remove featured image', 'lost_and_found' ),
'use_featured_image' => __( 'Use as featured image', 'lost_and_found' ),
'insert_into_item' => __( 'Insert into item', 'lost_and_found' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'lost_and_found' ),
'items_list' => __( 'Items list', 'lost_and_found' ),
'items_list_navigation' => __( 'Items list navigation', 'lost_and_found' ),
'filter_items_list' => __( 'Filter items list', 'lost_and_found' ),
);
$args = array(
'label' => __( 'Found', 'lost_and_found' ),
'description' => __( 'Found Post Type', 'lost_and_found' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', 'custom-fields', ),
'taxonomies' => array( 'petsfound', 'electronicsfound', 'countyfound' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'rewrite' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'found', $args );
}
add_action( 'init', 'found_custom_post_type', 5 );
}
function found_taxonomies_pets() {
$labels = array(
'name' => _x( 'Pets', 'taxonomy general name' ),
'singular_name' => _x( 'Pet', 'taxonomy singular name' ),
'search_items' => __( 'Search Pets' ),
'all_items' => __( 'All Pets' ),
'parent_item' => __( 'Parent Pets' ),
'parent_item_colon' => __( 'Parent Pet:' ),
'edit_item' => __( 'Edit Pet' ),
'update_item' => __( 'Update Pet' ),
'add_new_item' => __( 'Add New Pet' ),
'new_item_name' => __( 'New Pet' ),
'menu_name' => __( 'Pets' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'found/pets-found', 'with_front' => true ),
'show_admin_column' => true,
//'has_archive' => true
);
register_taxonomy( 'petsfound', 'found', $args );
flush_rewrite_rules();
}
add_action( 'init', 'found_taxonomies_pets', 1 );
- 我已多次重置永久链接。
- 我已经测试了将
hierarchical
andwith_front
值从 true 修改为 false 并再次修改,以防它们产生任何影响。 我
print_r($wp_query);
在 404.php 模板上运行,并在 query_vars 的开头收到以下内容:[query_vars] => Array ( [page] => 0 [found] => pets-found [post_type] => found [name] => pets-found
不知道还有什么可以看的,所以希望有人可以提供帮助。
干杯
达米安
编辑 - 添加 taxonomy-petsfound.php 的代码
<?php
/**
* The template for displaying Pets Found Taxonomy.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package dazzling
*/
get_header(); ?>
<div class="breadcrumb" typeof="BreadcrumbList" vocab="http://schema.org/">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>
<?php print_r($wp_query); ?>
<section id="primary" class="content-area col-sm-12 col-md-12 <?php echo of_get_option( 'site_layout' ); ?>">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<h1 class="page-title">
Found Items 2
</h1>
<?php
// Show an optional term description.
$term_description = term_description();
if ( ! empty( $term_description ) ) :
printf( '<div class="taxonomy-description">%s</div>', $term_description );
endif;
?>
</header><!-- .page-header -->
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php dazzling_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</section><!-- #primary -->
<?php get_footer(); ?>