簡體   English   中英

Wordpress single-custom_post_type模板未顯示

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM