0

我正在尝试创建一个名为“项目”的新自定义类型,但我的永久链接不起作用。这是我的代码:

function register_post_types() {
        $labels = array(
                    ...
                );

        $args = array(
            'labels' => $labels,
            'public' => true,
                        'has_archive' => false,
                        'rewrite' => array('with_front' => false, 'feeds' => false, 'pages' => false),
                        'supports' => array(
                            'title',
                            'editor',
                            'thumbnail',
                            'excerpt',
                            'comments'
                            )
                );

        register_post_type( 'projects', $args);      

即使通过手动更改永久链接(帖子名称 => 数字 => 帖子名称),我也会得到带有 url http://website.com/projects/my-project的 404。

调试时(我使用 Dev4press 技巧: http: //www.dev4press.com/2012/tutorials/wordpress/practical/debug-wordpress-rewrite-rules-matching/)这是我的结果:

<!-- Request: projects/my-project -->
<!-- Matched Rewrite Rule: projects/([^/]+)(/[0-9]+)?/?$ -->
<!-- Matched Rewrite Query: projects=my-project&amp;page= -->
<!-- Loaded Template: 404.php -->

你能帮我吗 ?

编辑: 奇怪的是,如果我更换

'rewrite' => array('with_front' => false, 'feeds' => false, 'pages' => false)

'rewrite' => array('slug' => 'p', 'with_front' => false, 'feeds' => false, 'pages' => false)

我可以访问http://website.com/p/my-project/,但如果我用“项目”更改 slug 我无法访问http://website.com/projects/my-project/: (

4

1 回答 1

0

转到管理面板中的设置 > 永久链接。点击保存按钮。看看会发生什么......

于 2012-06-06T09:58:47.193 回答