我创建了一个自定义帖子类型和与之关联的自定义分类法。单个帖子以及自定义帖子类型存档页面都可以正常工作。但是,无论尝试什么,分类分类存档页面都会返回“发现通知”。任何帮助将不胜感激。
这是我在functions.php中的CPT和分类法代码:
// Register Custom Post Type
function press_post_type() {
$labels = array(
'name' => _x( 'Press' ),
'singular_name' => _x( 'Press' ),
'menu_name' => __( 'Press' ),
'name_admin_bar' => __( 'Press' ),
'archives' => __( 'Press Archives' ),
'attributes' => __( 'Press Attributes' ),
'parent_item_colon' => __( 'Press:' ),
'all_items' => __( 'All Press' ),
'add_new_item' => __( 'Add New Press' ),
'add_new' => __( 'Add New' ),
'new_item' => __( 'New Press' ),
'edit_item' => __( 'Edit Press' ),
'update_item' => __( 'Update Press' ),
'view_item' => __( 'View Press' ),
'view_items' => __( 'View Press' ),
'search_items' => __( 'Search Press' ),
'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 press' ),
'items_list' => __( 'Press list' ),
'items_list_navigation' => __( 'Press list navigation' ),
'filter_items_list' => __( 'Filter press list' ),
);
$args = array(
'label' => __( 'Press' ),
'description' => __( 'Press' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions', 'custom-fields'),
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'has_archive' => true,
'rewrite' => array(
'slug' => 'press'
),
'can_export' => true,
'exclude_from_search' => false,
'yarpp_support' => true,
'taxonomies' => array(),
'publicly_queryable' => true,
'capability_type' => 'post'
);
register_post_type( 'press', $args );
}
add_action( 'init', 'press_post_type', 0 );
// Taxonomy for Custom Post Type
add_action( 'init', 'create_press_custom_taxonomy', 0 );
function create_press_custom_taxonomy() {
$labels = array(
'name' => _x( 'Topics', 'taxonomy general name' ),
'singular_name' => _x( 'Topic', 'taxonomy singular name' ),
'search_items' => __( 'Search Topics' ),
'all_items' => __( 'All Topics' ),
'parent_item' => __( 'Parent Topic' ),
'parent_item_colon' => __( 'Parent Topic:' ),
'edit_item' => __( 'Edit Topic' ),
'update_item' => __( 'Update Topic' ),
'add_new_item' => __( 'Add New Topic' ),
'new_item_name' => __( 'New Topic Name' ),
'menu_name' => __( 'Topics' ),
);
register_taxonomy('topics',array('press'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'public' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'topics' ),
));
}
这是taxonony-topics.php中的内容:
<?php
/**
* The template for displaying archive pages.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package understrap
*/
get_header();
?>
<?php
$container = get_theme_mod( 'understrap_container_type' );
?>
<div class="wrapper" id="archive-wrapper">
<div class="<?php echo esc_attr( $container ); ?>" id="content" tabindex="-1">
<div class="row">
<!-- Do the left sidebar check -->
<?php get_template_part( 'global-templates/left-sidebar-check' ); ?>
<main class="site-main" id="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
</header><!-- .page-header -->
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ),
'</a></h2>' ); ?>
<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php understrap_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif; ?>
<?php
$terms= get_terms(array('taxonomy'=>'topics'));
foreach($terms as $term){
echo '<a href="' . get_term_link($term) . '"><span>' . $term->name . '</span></a>';
}
?>
</header><!-- .entry-header -->
<?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>
<div class="entry-content">
<?php
the_excerpt();
?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php understrap_entry_footer(); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'loop-templates/content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
<!-- The pagination component -->
<?php understrap_pagination(); ?>
<!-- Do the right sidebar check -->
<?php get_template_part( 'global-templates/right-sidebar-check' ); ?>
</div> <!-- .row -->
</div><!-- Container end -->
</div><!-- Wrapper end -->
<?php get_footer(); ?>
答案 0 :(得分:0)
检出WordPress template文件文档
您只需创建archive- {your-post-type} .php文件即可为每种帖子类型使用不同的存档模板。
对于分类法:
taxonomy-{taxonomy}-{term}.php
taxonomy-{taxonomy}.php
tag-{slug}.php
tag-{id}.php
category-{slug}.php
category-{ID}.php