更改 WordPress 上的帖子永久链接结构以使用自定义分类法
我想更改 WordPress 3.0-beta1 上的帖子永久链接架构以使用新的自定义分类法。
今天我可以使用 /%category%/%postname%/
和 /my-category/my-post/
URL,这很好,但我需要使用另一个分类法“类”一。
我尝试使用 /%acervo%/%postname%/
但我的网址在 URL 上带有 %acervo%
而不是“Acevo”(我的分类名称)该帖子所属的。
我发现了与 WP_Rewrite 相关的内容,但没有成功......
I want to change the post permalink schema on my WordPress 3.0-beta1 to use my new custom taxonomy.
Today I can use /%category%/%postname%/
and the /my-category/my-post/
URL, that's nice but I need to use another taxonomy instead "category" one.
I tried to use /%acervo%/%postname%/
but my URLs came with %acervo%
on the URL instead the name of the "Acevo" (my taxonomy name) wich the post belongs to.
I found something related to WP_Rewrite but without sucess...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
这应该能解决问题。
function acervo_permalink($permalink, $post_id, $leavename){
if (get_option('permalink_structure') != ''){
$post = get_post($post_id);
$rewritecode = array(
'%acervo%'
);
if (strpos($permalink, '%acervo%') !== FALSE){
$terms = wp_get_object_terms($post->ID, 'acervo');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $acervo = $terms[0]->slug;
else $acervo = '';
}
$rewritereplace = array(
$acervo
);
$permalink = str_replace($rewritecode, $rewritereplace, $permalink);
}
return $permalink;
}
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以尝试使用 WordPress 插件,无类别库,并且然后使用帖子名通配符对分类进行硬编码,如下所示:
请注意,acervo 没有百分号,因为它是“硬编码”而不是通配符。
You could try using the WordPress plugin, No Category Base, and then hard code the taxonomy in with the postname wildcard, like so:
Note that acervo does not have the percentage signs since it's "hard coded" and not a wildcard.