WordPress 自定义帖子类型档案

发布于 2024-10-10 19:10:49 字数 859 浏览 3 评论 0原文

我已将以下内容添加到我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨敛清荷 2024-10-17 19:10:49

进入永久链接并保存设置以刷新永久链接结构。 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.

宛菡 2024-10-17 19:10:49

解决了该功能实际上尚未发布的问题。我必须下载测试版,但是这个版本的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文