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

2014-09-02 20:31:06 +08:00
 justfindu
服务器是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.

不管如何方法, 求
2628 次点击
所在节点    WordPress
6 条回复
shiniv
2014-09-02 20:49:51 +08:00
如果这样的话,parentCategory 的重写就跟 permalink 冲突了把
justfindu
2014-09-02 20:59:22 +08:00
@shiniv 对, 看样子是实在不行这样了 只能够parentCategory和subCategory都一样的重写吧...
webjin
2014-09-02 21:52:05 +08:00
Google字体我一直搞不定。
shiniv
2014-09-02 22:14:50 +08:00
@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
2014-09-02 22:33:30 +08:00
插件可以解决.
WP No Category Base
Removes '/category' from your category permalinks.
justfindu
2014-09-02 23:22:20 +08:00
@mjar 插件我试过 跟直接设置没差. 不仅去category.
@shiniv 好的 我试下 感谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/131381

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX