V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
justfindu
V2EX  ›  WordPress

Wordpress 的 分类链接的重写,一直搞不定.

  •  
  •   justfindu · 2014-09-02 20:31:06 +08:00 · 2607 次点击
    这是一个创建于 3495 天前的主题,其中的信息可能已经有所发展或是发生改变。
    服务器是apache, 可以使用htaccess.
    我使用了系统的permalink 设置使用的是 http://www.abc.com/sample-post/
    我现在分类需要这样显示:

    http://www.abc.com/category/parentCaegory/SubCategory/ ---> http://www.abc.com/parentCategory/Subcategory-someslug.html

    http://www.abc.com/category/parentCategory/ ---> http://www.abc.com/parentCategory

    真心求...

    我一开始在 主题的function中写了一个

    function twenty_category_link($link){

    $link = str_replace('category/','',$link);
    if(substr_count($link, '/') == 4){

    return $link;

    }else{

    $link = substr($link,0,strrpos($link, '-'));

    return $link.'-abcdefg.html';

    }

    }
    add_filter('category_link','twenty_category_link',1);

    把category输出链接...
    如果是parentCategory就输出为 http://www.abc.com/parentCategory
    如果是subCategory就输出为 http://www.abc.com/parentCategory/Subcategory-abcdefg.html

    其实就是根据原本应该输出的链接修改一下. 但是子目录会出现404 not found.

    不管如何方法, 求
    6 条回复    2014-09-02 23:22:20 +08:00
    shiniv
        1
    shiniv  
       2014-09-02 20:49:51 +08:00   ❤️ 1
    如果这样的话,parentCategory 的重写就跟 permalink 冲突了把
    justfindu
        2
    justfindu  
    OP
       2014-09-02 20:59:22 +08:00
    @shiniv 对, 看样子是实在不行这样了 只能够parentCategory和subCategory都一样的重写吧...
    webjin
        3
    webjin  
       2014-09-02 21:52:05 +08:00
    Google字体我一直搞不定。
    shiniv
        4
    shiniv  
       2014-09-02 22:14:50 +08:00   ❤️ 1
    @justfindu 给个参考你,要生效就要到固定链接那里保存一下即可。
    function rewrite_category_rules($rules) {
    $rewrite = array(
    'category/(.+?)/?$' => 'index.php?category_name=$matches[1]',
    'category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
    'category/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
    'category/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
    );
    return array_merge($rewrite, $rules);
    }
    add_filter('post_rewrite_rules', 'rewrite_category_rules');


    @webjin google 字体要么替换,要么禁用~ 搜索一下一堆堆的
    mjar
        5
    mjar  
       2014-09-02 22:33:30 +08:00   ❤️ 1
    插件可以解决.
    WP No Category Base
    Removes '/category' from your category permalinks.
    justfindu
        6
    justfindu  
    OP
       2014-09-02 23:22:20 +08:00
    @mjar 插件我试过 跟直接设置没差. 不仅去category.
    @shiniv 好的 我试下 感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3638 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:15 · PVG 08:15 · LAX 17:15 · JFK 20:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.