WordPress 自定义帖子类型档案
我已将以下内容添加到我的functions.php 文件中
register_post_type( 'news',
array(
'labels' => array(
'name' => __( 'News' ),
'singular_name' => __( 'News' ),
'add_new' => __( 'Add New Article' ),
'add_new_item' => __( 'Add Article' ),
'edit_item' => __( 'Edit Article' ),
'new_item' => __( 'New Article' ),
'view_item' => __( 'View Article' ),
'search_items' => __( 'Search Articles' ),
'not_found' => __( 'No Articles Found' ),
'not_found_in_trash' => __( 'No Articles Found In Trash' ),
'rewrite' => array(
'slug' => 'news',
'with_front' => false
),
'has_archive' => true,
),
'public' => true,
)
);
但是,当我在我的网站 mysite/news/ 之后输入新闻时,我得到一个未找到的页面,而我应该收集该页面,并使用 has_archives 选项列出我的新闻档案。
我做错了什么!!!
顺便说一句,我有一个 archives.php 文件
I have added the following to my functions.php file
register_post_type( 'news',
array(
'labels' => array(
'name' => __( 'News' ),
'singular_name' => __( 'News' ),
'add_new' => __( 'Add New Article' ),
'add_new_item' => __( 'Add Article' ),
'edit_item' => __( 'Edit Article' ),
'new_item' => __( 'New Article' ),
'view_item' => __( 'View Article' ),
'search_items' => __( 'Search Articles' ),
'not_found' => __( 'No Articles Found' ),
'not_found_in_trash' => __( 'No Articles Found In Trash' ),
'rewrite' => array(
'slug' => 'news',
'with_front' => false
),
'has_archive' => true,
),
'public' => true,
)
);
But when i type in news after my site mysite/news/ I get a page not found when it should I gather be listing my archives for news with the has_archives option.
What am I doing wrong!!!
By the way I have an archives.php file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
进入永久链接并保存设置以刷新永久链接结构。 WordPress 的自定义帖子类型永久链接存在问题,每次更改自定义帖子类型时都必须执行此操作。这将防止您收到 404 错误。
Go into permalinks and save the settings to refresh the permalink structure. Wordpress has a problem with the custom post type permalinks you have to do this every time you make a change to you custom post type. This will prevent your from getting a 404 error.
解决了该功能实际上尚未发布的问题。我必须下载测试版,但是这个版本的 WordPress 很快就要到期了。
Solved its not actually been released yet, the feature. I had to download the beta version however this version of wordpress is due soon.