[英]Wordpress single-custom_post_type template not showing
您好,我创建了一个自定义帖子类型,并且single-custom_post_type显示了索引页面,而不是帖子类型页面。
我不明白为什么它显示索引页面。
我刷新了永久链接,使用了: flush_rewrite_rules();
,但不起作用
事务所,tv.php
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
test
<?php endwhile; endif; ?>
<!-- series -->
<?php get_footer(); ?>
注册职位类型
function tvshows_taxonomy() {
register_taxonomy('tv_categories', array('tv,episodes',),
array(
'show_admin_column' => true,
'hierarchical' => true,
'rewrite' => array('slug' => get_option('tv-category')),)
);
}
add_action('init', 'tvshows_taxonomy', 0);
function prefijo_series() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'prefijo_series' );
// Register Series
function series() {
$labels = array(
'name' => _x( 'TV Shows', 'Post Type General Name', 'theme_name' ),
'singular_name' => _x( 'TV Show', 'Post Type Singular Name', 'theme_name' ),
'menu_name' => __( 'TV Shows', 'theme_name' ),
'name_admin_bar' => __( 'TV Shows', 'theme_name' ),
);
$rewrite = array(
'slug' => 'tv',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __( 'TV Show', 'theme_name' ),
'description' => __( 'TV series manage', 'theme_name' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail','comments' ),
'taxonomies' => array( 'tv_categories' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-welcome-view-site',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
);
register_post_type( 'tv', $args );
}
add_action( 'init', 'series', 0 );
有人能帮我吗?
史密斯,
您的代码没什么可更改的。 只需转到后端管理部分,然后单击设置->永久链接,然后在单选按钮中选择“发布名称”,然后单击保存更改。 完成。
刷新单个页面即可使用。
我要说的是您对flush_rewrite_rules()
调用实际上并未运行。 可以肯定的是,将快速手动刷新添加到例如functions.php
:
/* Trigger on wp-admin or cron and whathaveyou */
add_action('admin_init', function() {
flush_rewrite_rules();
});
在活动站点上的init上进行刷新会降低性能等。但是理智检查您的刷新很有用。
固定,我只包括管理员的注册职位类型。 这是问题所在
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.