自定义帖子类型不显示 Single.php
我无法理解为什么我的博客没有显示 single.php 或 single.php 页面。到目前为止,我已经尝试了注册 post_type 的不同选项,并尝试重置永久链接,但没有成功。
我的functions.php中的代码
<?php
function wpdocs_create_blog_taxonomies()
{
$labels = array(
'name' => _x('Blog', 'taxonomy general name', 'textdomain'),
'menu_name' => __('Blog Categories', 'textdomain'),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'show_in_rest' => true,
'has_archive' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array('slug' => 'blog'),
);
register_taxonomy('blog_categories', 'blog', $args);
}
add_action('init', 'wpdocs_create_blog_taxonomies', 0);
function create_posttype()
{
register_post_type(
'blog',
array(
'labels' => array(
'name' => ('blog')
),
'hierarchical' => true,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'taxonomies' => array('blog_categories', 'blog'),
'supports' => array('title', 'editor', 'thumbnail'),
)
);
}
add_action('init', 'create_posttype');
Can't wrap my head around it why my blog isn't showing single.php or single.php page. So far I have tried different options where I register post_type and also tried to reset permalinks but no luck.
Code in my functions.php
<?php
function wpdocs_create_blog_taxonomies()
{
$labels = array(
'name' => _x('Blog', 'taxonomy general name', 'textdomain'),
'menu_name' => __('Blog Categories', 'textdomain'),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'show_in_rest' => true,
'has_archive' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array('slug' => 'blog'),
);
register_taxonomy('blog_categories', 'blog', $args);
}
add_action('init', 'wpdocs_create_blog_taxonomies', 0);
function create_posttype()
{
register_post_type(
'blog',
array(
'labels' => array(
'name' => ('blog')
),
'hierarchical' => true,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'taxonomies' => array('blog_categories', 'blog'),
'supports' => array('title', 'editor', 'thumbnail'),
)
);
}
add_action('init', 'create_posttype');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,这是重复的 slug 名称的问题。不能有具有相同名称的页面。就我而言,它是博客。
Turns out it was an issue with repeating slug names. Can't have page with same slug name. In my case it was blog.