删除自定义帖子类型插件,但保留相关类别分类永久链接

时间:2016-03-21 作者:Lorenzo Beltrame

在自定义帖子类型分类法的自定义url重写方面也遇到了困难。

以下是我的要求:

域/mycpt\\u类别/postname/

有很好的记录here 在多个SE线程中,删除CPT basename,从而得到永久链接:

域名/postname/

我能够构建permalink,例如:

域/cpt基名称/cpt\\U类别/postname(following this solution )

我真正想做的是删除自定义的post类型slug,但保留其相关的分类类别,这样我的链接将是:

域/mycpt\\u类别/postname/

非常感谢您在这方面的帮助。

1 个回复
SO网友:Craig Pearson

注册自定义帖子类型时,是否尝试在重写数组中使用\\u front禁用?例如,使用post type book的示例:

add_action( \'init\', \'codex_book_init\' );
/**
 * Register a book post type.
 *
 * @link http://codex.wordpress.org/Function_Reference/register_post_type
 */
function codex_book_init() {
    $labels = array(
        \'name\'               => _x( \'Books\', \'post type general name\', \'your-plugin-textdomain\' ),
        \'singular_name\'      => _x( \'Book\', \'post type singular name\', \'your-plugin-textdomain\' ),
        \'menu_name\'          => _x( \'Books\', \'admin menu\', \'your-plugin-textdomain\' ),
        \'name_admin_bar\'     => _x( \'Book\', \'add new on admin bar\', \'your-plugin-textdomain\' ),
        \'add_new\'            => _x( \'Add New\', \'book\', \'your-plugin-textdomain\' ),
        \'add_new_item\'       => __( \'Add New Book\', \'your-plugin-textdomain\' ),
        \'new_item\'           => __( \'New Book\', \'your-plugin-textdomain\' ),
        \'edit_item\'          => __( \'Edit Book\', \'your-plugin-textdomain\' ),
        \'view_item\'          => __( \'View Book\', \'your-plugin-textdomain\' ),
        \'all_items\'          => __( \'All Books\', \'your-plugin-textdomain\' ),
        \'search_items\'       => __( \'Search Books\', \'your-plugin-textdomain\' ),
        \'parent_item_colon\'  => __( \'Parent Books:\', \'your-plugin-textdomain\' ),
        \'not_found\'          => __( \'No books found.\', \'your-plugin-textdomain\' ),
        \'not_found_in_trash\' => __( \'No books found in Trash.\', \'your-plugin-textdomain\' )
    );

    $args = array(
        \'labels\'             => $labels,
                \'description\'        => __( \'Description.\', \'your-plugin-textdomain\' ),
        \'public\'             => true,
        \'publicly_queryable\' => true,
        \'show_ui\'            => true,
        \'show_in_menu\'       => true,
        \'query_var\'          => true,
        \'rewrite\'            => array( \'slug\' => \'book\', \'with_front\' => false ),
        \'capability_type\'    => \'post\',
        \'has_archive\'        => true,
        \'hierarchical\'       => false,
        \'menu_position\'      => null,
        \'supports\'           => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
    );

    register_post_type( \'book\', $args );
}
但是,上面的示例没有包含您提到的重写,因此请确保调整您的重写参数以适应。

相关推荐