Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义post类型存档页返回空白_Php_Wordpress_Custom Post Type_Archive - Fatal编程技术网

Php 自定义post类型存档页返回空白

Php 自定义post类型存档页返回空白,php,wordpress,custom-post-type,archive,Php,Wordpress,Custom Post Type,Archive,我通过我制作的cutom插件创建了一个带有slug plist的CPT 在我的本地主机中,存档可以工作,但在live server中,它返回空白页 这是存档页面代码 /** * Add Price List archive template * @since 1.0.0 */ add_filter( 'archive_template', 'get_plist_archive_template' ) ; function get_plist_archive_template( $arc

我通过我制作的cutom插件创建了一个带有slug plist的CPT

在我的本地主机中,存档可以工作,但在live server中,它返回空白页

这是存档页面代码

/**
 * Add Price List archive template
 * @since    1.0.0
*/
add_filter( 'archive_template', 'get_plist_archive_template' ) ;
function get_plist_archive_template( $archive_template ) {
     global $post;

     if ( is_post_type_archive ( 'plist' ) ) {
          $archive_template = dirname( __FILE__ ) . '\partials\archive-plist.php';
     }
     return $archive_template;
}
链接:

这也可能有助于:

/**
 * Register Custom Post Type Price List
 * @since    1.0.0
*/
if ( ! function_exists('price_item_post_type') ) {
    add_action( 'init', 'price_item_post_type', 0 );
    // Register Custom Post Type
    function price_item_post_type() {

        $labels = array(
            'name'                  => _x( 'Price Lists', 'Post Type General Name', 'plist' ),
            'singular_name'         => _x( 'Price List', 'Post Type Singular Name', 'plist' ),
            'menu_name'             => __( 'Price List', 'plist' ),
            'name_admin_bar'        => __( 'Price List', 'plist' ),
            'archives'              => __( 'Price List Archives', 'plist' ),
            'attributes'            => __( 'Price List Attributes', 'plist' ),
            'parent_item_colon'     => __( 'Parent Price List:', 'plist' ),
            'all_items'             => __( 'All Price Lists', 'plist' ),
            'add_new_item'          => __( 'Add New Price List', 'plist' ),
            'add_new'               => __( 'Add New', 'plist' ),
            'new_item'              => __( 'New Price List', 'plist' ),
            'edit_item'             => __( 'Edit Price List', 'plist' ),
            'update_item'           => __( 'Update Price List', 'plist' ),
            'view_item'             => __( 'View Price List', 'plist' ),
            'view_items'            => __( 'View Price Lists', 'plist' ),
            'search_items'          => __( 'Search Price List', 'plist' ),
            'not_found'             => __( 'Not found', 'plist' ),
            'not_found_in_trash'    => __( 'Not found in Trash', 'plist' ),
            'featured_image'        => __( 'Featured Image', 'plist' ),
            'set_featured_image'    => __( 'Set featured image', 'plist' ),
            'remove_featured_image' => __( 'Remove featured image', 'plist' ),
            'use_featured_image'    => __( 'Use as featured image', 'plist' ),
            'insert_into_item'      => __( 'Insert into Price List', 'plist' ),
            'uploaded_to_this_item' => __( 'Uploaded to this Price List', 'plist' ),
            'items_list'            => __( 'Price Lists', 'plist' ),
            'items_list_navigation' => __( 'Price Lists navigation', 'plist' ),
            'filter_items_list'     => __( 'Filter Price Lists', 'plist' ),
        );
        $args = array(
            'label'                 => __( 'Price List', 'plist' ),
            'description'           => __( 'Price list item for market', 'plist' ),
            'labels'                => $labels,
            'supports'              => array( ),
            'hierarchical'          => false,
            'public'                => true,
            'show_ui'               => true,
            'show_in_menu'          => true,
            'menu_position'         => 20,
            'menu_icon'             => 'dashicons-tag',
            'show_in_admin_bar'     => true,
            'show_in_nav_menus'     => true,
            'can_export'            => true,
            'has_archive'           => true,        
            'exclude_from_search'   => true,
            'publicly_queryable'    => true,
            'capability_type'       => 'page',
        );
        register_post_type( 'plist', $args );

    }

}

我尝试了刷新重写规则,但没有成功。

首先需要确保您的自定义帖子类型在代码中启用了存档。要做到这一点,您需要转到您的自定义帖子类型代码,这些代码可以在您的主题的functions.php文件或特定于站点的插件文件中找到。您需要确保已将_archive参数设置为true

示例代码如下所示:

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'plist',
        array(
            'labels' => array(
                'name' => __( 'plist' ),
                'singular_name' => __( 'plist' )
            ),
        'public' => true,
        'has_archive' => true,
        )
    );
}