Php 自定义文章类型单页不工作

Php 自定义文章类型单页不工作,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,我有aj fashions定制贴子类型。从技术上讲,我试图在名为fashio-template.php的模板文件中显示所有帖子的循环,现在为单个帖子创建了文件single-fashions.php。我仍然得到404页错误未找到 敬请指教,以下是我的代码 add_action( 'init', 'fashion' ); function fashion() { register_post_type( 'aj-fashion', array( 'labels' => a

我有aj fashions定制贴子类型。从技术上讲,我试图在名为fashio-template.php的模板文件中显示所有帖子的循环,现在为单个帖子创建了文件single-fashions.php。我仍然得到404页错误未找到

敬请指教,以下是我的代码

add_action( 'init', 'fashion' );
function fashion() {
  register_post_type( 'aj-fashion',
    array(
      'labels' => array(
        'name' => __( 'AJ Fasions' ),
        'singular_name' => __( 'AJ Fashion' )
      ),
        'public' => true,
        'has_archive' => true,
        'show_ui' => true,
        'hierarchical' => false,
        'rewrite' => array('slug' => 'aj-fashions',),
        'supports'=> array( 'title', 'editor', 'thumbnail', 'author' ),
    )
  );
}

对单个模板使用
single-{posttype}.php
。另外,如果您使用
has_archive
参数将post类型注册为true,那么您可以对归档模板使用
archive-{posttype}.php
,这将允许您跳过那里的查询,因为全局
$wp_query
对象已经填充了您的自定义post类型

在您的案例中,检查下面的示例


single fashions.php
而不是
single aj fashion.php

使用
single-{posttype}.php
作为单个模板。另外,如果您使用
has_archive
参数将post类型注册为true,那么您可以对归档模板使用
archive-{posttype}.php
,这将允许您跳过那里的查询,因为全局
$wp_query
对象已经填充了您的自定义post类型

在您的案例中,检查下面的示例


single fashions.php
而不是
single aj fashion.php
创建single-{posttype}.php后,只需更新permalink即可。进入设置->永久链接。每个开发人员第一次面对这个问题

创建single-{posttype}.php后,只需更新permalink即可。进入设置->永久链接。每个开发人员第一次面对这个问题

创建single-{posttype}.php后,只需更新permalink即可

这比使用这个函数更有效

放入functions.php
刷新或重写规则(错误)

创建single-{posttype}.php后,只需更新permalink即可

这比使用这个函数更有效

放入functions.php
刷新或重写规则(错误)

我也遇到了同样的问题,但将通过以下代码替换来解决:

函数寄存器{

}
添加操作('init','register\u fashion',0)

我也遇到了同样的问题,但将通过以下代码替换来解决:

函数寄存器{

}
添加操作('init','register\u fashion',0)

添加刷新\重写\规则();工作。什么是单贴特定的帖子循环???从设置更新永久链接。它工作了我在永久链接和它的工作中添加了post$post->ID。。。谢谢大家…添加刷新重写规则();工作。什么是单贴特定的帖子循环???从设置更新永久链接。它工作了我在永久链接和它的工作中添加了post$post->ID。。。谢谢大家…我的自定义帖子类型=“aj-fasion”,这就是为什么我把它命名为single-aj-fashion.php?我做错了吗。请注意,您没有错,但这是wordpress标准,无论您在
register\u post\u type
中使用了什么slug,slug都需要添加在single ex:
single-{posttypeslug}.php
之后。它对你有用吗?我的自定义帖子type=“aj fasion”,这就是为什么我将它命名为single-aj-fashion.php?我做错了吗。请注意,您没有错,但这是wordpress标准,无论您在
register\u post\u type
中使用了什么slug,slug都需要添加在single ex:
single-{posttypeslug}.php
之后。它是否适用于您?创建新模板应该不会影响此解决方案的工作,因为它将默认为其他模板。此处仅与“设置->永久链接”相关。创建新模板不会影响此解决方案的工作,因为它将默认为其他模板。此处仅与“设置->永久链接”相关。
$labels = array(
    'name'                  => 'AJ Fasions',
    'singular_name'         => 'AJ Fasion',
    'menu_name'             => 'AJ Fasions',
    'name_admin_bar'        => 'AJ Fasion',
    'archives'              => 'ajfashionArchives',
    'attributes'            => 'Item Attributes',
    'parent_item_colon'     => 'Parent Item:',
    'all_items'             => 'All Items',
    'add_new_item'          => 'Add New Item',
    'add_new'               => 'Add New',
    'new_item'              => 'New Item',
    'edit_item'             => 'Edit Item',
    'update_item'           => 'Update Item',
    'view_item'             => 'View Item',
    'view_items'            => 'View Items',
    'search_items'          => 'Search Item',
    '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 item',
    'items_list'            => 'Items list',
    'items_list_navigation' => 'Items list navigation',
    'filter_items_list'     => 'Filter items list',
);
$args = array(
    'label'                 => 'AJ Fasion',
    'description'           => 'Post Type Description',
    'labels'                => $labels,
    'supports'              => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
    'taxonomies'            => array( 'fashion_category' ),
    'hierarchical'          => false,
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 5,
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'can_export'            => true,
    'has_archive'           => true,
    'exclude_from_search'   => false,
    'publicly_queryable'    => true,
    'capability_type'       => 'post',
);
register_post_type( 'aj-fashion', $args );