繁体   English   中英

如何在 URL 中将 Custom Post Type Slug 更改为 Taxonomy Slug?

[英]How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?

(原谅我,我知道这个问题已经被广泛提出,但我还没有找到适合我的答案)

我正在开发一个网络漫画网站。 我有一个名为“comic-page”(用于单个漫画页面)的自定义帖子类型和一个名为“comic-series”的分类法(因为我计划让漫画跨越多个系列)。 现在,典型漫画页面的 URL 如下所示:

http://localhost/wordpress/comic-page/page-01/

当我希望它看起来像:

http://localhost/wordpress/lcc/page-01/ 

(其中“lcc”是特定系列的蛞蝓)

我尝试了几种方法,它们成功地从 URL 中删除了“comic-page”,但没有一个方法将“lcc”引入 URL。 我当前的工作代码如下(我已经取出了删除“漫画页”的位):

漫画页面帖子类型:

/* === Comic Page === */
function post_type_comic_page() {
    
    // Labels
    $labels = array(
        'name' => 'Comic Pages',
        'singular_name' => 'Comic Page',
        'add_new' => 'Add New Comic Page',
        'add_new_item' => 'Add Comic Page',
        'all_items' => 'All Comic Pages',
        'edit_item' => 'Edit Comic Page',
        'not_found' => 'No Comic Pages Found',
        'not_found_in_trash' => 'No Comic Pages Found in Trash',
    );
    
    // Arguments
    $args = array(
        'labels' => $labels,
        'public' => true,
        'menu_icon' => 'dashicons-book-alt',
        'hierarchical' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'publicly_queryable' => true,
        'supports' => array( 'title', 'page-attributes' ),
    );
    
    // Register Comic Pages Post Type
    register_post_type('comic-page', $args);
}

add_action('init', 'post_type_comic_page');

系列分类:

/* === Comic Series Taxonomy === */
function taxonomy_comic_series() {
    
    // Labels
    $labels = array(
        'name' => 'Series',
        'singular_name' => 'Series',
        'add_new' => 'Add New',
        'add_new_item' => 'Add Series',
        'all_items' => 'All Series',
        'edit_item' => 'Edit Series',
        'not_found' => 'No Series Found',
        'not_found_in_trash' => 'No Series Found in Trash',
    );
    
    // Arguments
    $args = array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'comic-series', 'with_front' => false ),
    );
    
    // Register Comic Page Type Taxonomy
    register_taxonomy('comic-series', 'comic-page', $args);
}

add_action('init', 'taxonomy_comic_series');

我的最终目标是能够 select 特定漫画页面所属的系列在页面本身上,然后让我在 WordPress 后端分配的相应 slug 出现在 ZE6B391A8D2C4D45702A23 中。 我确信有一种方法可以实现您认为相对简单的事情,但我无法弄清楚。 任何人都可以帮忙吗?

好吧,这不是很典型,只要我在这里问,我终于找到了答案:

https://wordpress.stackexchange.com/questions/94817/add-category-base-to-url-in-custom-post-type-taxonomy/94820

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM