【问题标题】:Wordpress hide category from url structureWordpress 从 url 结构中隐藏类别
【发布时间】:2016-10-27 20:52:19
【问题描述】:

我有这样的 url 结构

http://www.domain.dom/blog/%category%/%postname%/

在主题functions.php中遵循规则

function wpa58471_category_base() {
// Remember to flush the rules once manually after you added this code!
add_rewrite_rule(
    // The regex to match the incoming URL
    'blog/([^/]+)/([^/]+)/([^/]+)(/[0-9]+)?/?$',
    // The resulting internal URL
    'index.php?category_name=$matches[1]/$matches[2]&name=$matches[3]&paged=$matches[4]',
    // Add the rule to the top of the rewrite list
    'top' );
}

在此站点上找到的代码

所以现在浏览器中的 url 看起来像这样: http://www.domain.dom/blog/cars/new-car-on-market/

问题:

当用户想要浏览汽车类别中的所有帖子时,网址是:

http://www.domain.dom/blog/category/cars/

我想隐藏 /category/ 部分。有可能吗?

谢谢

【问题讨论】:

    标签: php wordpress apache mod-rewrite


    【解决方案1】:

    你可以试试Remove Category URL插件。

    关注此博客How To Remove Category From Your URLs In WordPress

    【讨论】:

    • 我已经有了 Yoast SEO 插件,所以这很容易解决。谢谢
    • 始终欢迎提供指向潜在解决方案的链接,但请add context around the link,以便您的其他用户知道它是什么以及为什么存在。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久离线。考虑到仅仅是指向外部站点的链接Why and how are some answers deleted? 的一个可能原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    相关资源
    最近更新 更多