如何去除 wordpress 自定义文章类型的 URL 前缀?

2016-10-29 23:28:28 +08:00
 ErnieSauce
if ( ! function_exists( 'themewich_create_taxonomies' ) ) :
function themewich_create_taxonomies() {
$labels = array(
'name' => _x( 'Filter', 'taxonomy general name', 'framework' ),
'singular_name' => _x( 'Filter', 'taxonomy singular name', 'framework' ),
'search_items' => __( 'Search Filters', 'framework' ),
'all_items' => __( 'All Filters', 'framework' ),
'parent_item' => __( 'Parent Filter', 'framework' ),
'parent_item_colon' => __( 'Parent Filter:', 'framework' ),
'edit_item' => __( 'Edit Filter', 'framework' ),
'update_item' => __( 'Update Filter', 'framework' ),
'add_new_item' => __( 'Add New Filter', 'framework' ),
'new_item_name' => __( 'New Filter Name', 'framework' ),
'menu_name' => __( 'Filters', 'framework' ),
);

register_taxonomy( 'filter',
array( 'portfolio', 'post' ),
array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'filter' ), // This is the url slug
)
);
}


使用以上代码新添了自定义文章类型
目录结构 URL 为 http://xxx.com/filter/aaa( http://xxx.com/filter/aaa(aaa 为自定义的目录别名)
文章结构 URL 为 http://xxx.com/portfolio/xxx

现在我想将目录结构的 url 更换为 http://xxx.com/aaa 也就是去除 filter
文章结构为 http://xxx.com/aaa/xxx

使用下面代码

if ( $post->post_type == 'portfolio' ){
return home_url( 'one/' . $post->ID .'.html' );
} else {
return $link;
}

文章结构变成了 http://xxx.com/one/xxx 而不是 aaa

求解 谢谢 不胜感激
2821 次点击
所在节点    PHP
0 条回复

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

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

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

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

© 2021 V2EX