【问题标题】:Permalinks with custom post type in Wordpress在 Wordpress 中具有自定义帖子类型的永久链接
【发布时间】:2012-06-10 04:56:49
【问题描述】:

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

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/ :(

【问题讨论】:

    标签: wordpress mod-rewrite url-rewriting


    【解决方案1】:

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

    【讨论】:

    • 谢谢Kashif,不幸的是,每当我使用flush rewrite rules()函数修改我的源代码时,我都会记录我的重写规则,我遇到了同样的问题。
    猜你喜欢
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多