自定义帖子类型单页不起作用

Sal*_*zak 1 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' => 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' ),
    )
  );
}
Run Code Online (Sandbox Code Playgroud)

小智 6

创建 single-{posttype}.php 后,您只需更新您的永久链接。进入设置->永久链接。每个开发人员都是第一次遇到这个问题。