【问题标题】:Show different URL in address bar在地址栏中显示不同的 URL
【发布时间】:2018-06-01 14:04:54
【问题描述】:

我有一个帖子类型为“播客”的自定义帖子,现在我的播客帖子单个 URL 是 http://localhost/sitename/blog/podcast/post-name。但我想显示帖子类型的“播客”网址,例如:http://localhost/sitename/test/podcast/post-name

当前站点永久链接设置为带有/blog/%postname% 的自定义结构。因此,博客与每种自定义帖子类型一起显示。我想保持永久链接结构相同,但博客不会显示在“播客”帖子 URL 中。

我已经为单个播客创建了一个新文件,其中复制了 single.php 并将名称更改为 single-podcast.phphttp://localhost/xyz/blog/podcast/post-name 可以正常工作,但我想在 URL 中显示不同的名称。

您能否为此提出解决方案?

【问题讨论】:

    标签: wordpress .htaccess url custom-post-type permalinks


    【解决方案1】:

    您是否尝试过重写选项? https://codex.wordpress.org/Function_Reference/register_post_type#Parameters

    例子:

    [
        'rewrite'   => [
            'slug'         => 'your/custom/post/slug/here',
            'with_front'   => false,
        ],
    ]
    

    【讨论】:

    • 是的,我添加了以下内容,并且 url 正在创建我想要的内容,但我找不到页面。 $args = array("label" => __("Podcasts", ""), "public" => false, "publicly_queryable" => true, "show_ui" => true, "show_in_rest" => false, "has_archive " => false, "show_in_menu" => true, "capability_type" => "post", "hierarchical" => false, "rewrite" => array("slug" => "/abc/podcast", "with_front" => false ), "query_var" => true, "taxonomies" => array( "category" ), );
    • 在设置自定义帖子类型 slug 后尝试保存永久链接(设置 -> 永久链接 -> 再次保存),然后重试。它应该工作:)
    • 请注意,此代码使用现代数组简写(仅使用 [] 进行数组定义)但旧 php - 5.3 以下的版本 - 会出错。如果您将方括号替换为完整版的 array() 时出错。
    猜你喜欢
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    • 2015-04-23
    • 2023-03-28
    • 2014-04-04
    • 2013-01-12
    相关资源
    最近更新 更多