3
嗨目前特定类别的职位分开的永久链接结构,在我们的WordPress我们默认的永久链接结构是如何保持在WordPress
abc.com/%postname%-%post_id%.html
但对特定的类别我想不同的永久链接结构 例如:为照片分类我希望URL结构
abc.com/%post_id%.html
目前我使用下面的代码,但它不工作
add_filter('post_link', 'custom_permalink', 10, 3);
function custom_permalink($permalink, $post, $leavename) {
// Get the categories for the post
$category = get_the_category($post->ID);
if ( !empty($category) && $category[0]->cat_name == "Photos") {
$permalink = home_url('/'.$post->ID .'.html');
}
return $permalink;
}
但是我没有得到不同的特定类别帖子的固定链接结构。请帮帮我。
无论何时您尝试更改固定链接设置,您还需要刷新重写规则以更新它们(可以检查数据库以验证这一点)。如果您没有执行'flush_rewite_rules()'或转到后端的'permalink'页面,并点击'Save'刷新规则,您写的代码从未受到影响。 – Ohgodwhy