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

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

  •  
  •   ErnieSauce · 2016-10-29 23:28:28 +08:00 · 2790 次点击
    这是一个创建于 2707 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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

    求解 谢谢 不胜感激
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5181 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:32 · PVG 17:32 · LAX 02:32 · JFK 05:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.