我有自定义帖子类型的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' ),
)
);
}
创建单{posttype} .php之后您只需更新固定链接即可。得到设置 - >永久链接。每个开发人员第一次面临这个问题。
使用single-{posttype}.php
作为单个模板。此外,如果您在has_archive
参数设置为true的情况下注册您的帖子类型,那么您可以使用archive-{posttype}.php
作为您的存档模板,这将允许您跳过您在那里的查询,因为全局$wp_query
对象已经填充了您的自定义帖子类型。
在你的情况下检查下面的例子
single-fashions.php
而不是single-aj-fashion.php
。
创建单{posttype} .php之后您只需更新固定链接即可。
这不会比使用这个功能更有效
放入functions.php flush_rewrite_rules(false);