問題描述

我在 Webiverse 中看到很多關於將頁面分配為自定義帖子類型的父項的帖子。四個小時後,我找不到解決方案,需要一些幫助。我創建了一個”About” 頁面,它是”Our People” 頁面的父級。我還創建了一個名為”People” 的自定義帖子類型。併為”Our People” 頁面創建了一個自定義頁面模板。固定鏈接結構看起來很好,直到你到達單個”people” 頁面。例如:約翰·史密斯的頁面,固定鏈接是不正確的。

自定義帖子類型:

期望的固定鏈接結構:/about-us /our-people /john-smith

實際連結結構:/our-people /john-smith

我們的人物頁面結構:/about-us /our-people

“about-us” 是一個頁面,”our-people” 是一個頁面,也是自定義帖子類型的塊重寫,”people” 。我試圖改變層次結構設置,我已經嘗試將”about-us/our-people” 直接添加到重寫中,沒有成功。

的 functions.php:

function codex_custom_init() {
    // Our People
    $people_label = array(
        'name' => 'People',
        'singular_name' => 'People',
        'add_new' => 'Add People',
        'add_new_item' => 'Add New People',
        'edit_item' => 'Edit People',
        'new_item' => 'New People',
        'all_items' => 'All People',
        'view_item' => 'View People',
        'search_items' => 'Search People',
        'not_found' => 'No People found',
        'not_found_in_trash' => 'No People found in Trash',
        'parent_item_colon' => '',
        'menu_name' => 'People',
    );
    $people_args = array (
        'labels' => $people_label,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'our-people'),
        'capability_type' => 'page',
        'has_archive' => true,
        'hierarchical' => true,
        'menu_position' => null,
        'menu_icon' => get_template_directory_uri() . '/images/icons/people.png',
        'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt','page-attributes'),
    );

    register_post_type('people', $people_args);
}

我的自定義模板:people.php people-single.php

最佳解決方案

這應該工作:

'rewrite' => array( 'slug' => 'about-us/our-people'),

結合:

'has_archive' => false,

在進行更改以刷新重寫規則後,請務必訪問管理員中的 「固定鏈接」 設置頁面。

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。