Wordpress - 如何在注册自定义帖子后更改自定义帖子的永久链接

时间:2014-01-16 16:21:15

标签: wordpress custom-post-type permalinks

在我的项目中,我使用了一个名为'ABSOLUTE'的主题。该主题在注册名为“投资组合”的自定义帖子时有自己的语言。代码不是php,所以我通过将“portfolio”的标签更改为“cheat / guides /。”来制作肮脏的技巧。

//change post labels
function change_post_object_label() {
global $wp_post_types;
    $labels = &$wp_post_types['portfolio']->labels;
    $labels->name = 'Guides/Cheats';
    $labels->singular_name = 'Guide/Cheat';
    $labels->add_new = 'Add Guide/Cheat';
    $labels->add_new_item = 'Add Guide/Cheat';
    $labels->edit_item = 'Edit Guide/Cheat';
    $labels->new_item = 'Guide/Cheat';
    $labels->all_items = 'All Guide/Cheat';
    $labels->view_item = 'View Guide/Cheat';
    $labels->search_items = 'Search Guide/Cheat';
    $labels->not_found = 'No Guides/Cheats found';
    $labels->not_found_in_trash = 'No Guides/Cheats found in Trash';   
}
add_action( 'init', 'change_post_object_label', 999 );

//change menu label of Portfolio in the admin
function change_post_menu_label() {
    global $menu;
    $menu[7][0] = 'Guides/Cheats'; 
}
add_action( 'admin_menu', 'change_post_menu_label' );


//change taxonomy labels
function wpa4182_init()
{
    global $wp_taxonomies;

    $wp_taxonomies['portfolio_category']->labels = (object)array(
        'name' => 'Guide/Cheat Categories',
        'menu_name' => 'Guide/Cheat Categories',
        'singular_name' => 'Guide/Cheat Category',
        'search_items' => 'Search Guide/Cheat Category',
        'popular_items' => 'Popular Guide/Cheat Categories',
        'all_items' => 'All Categories',
        'parent_item' => null, // Tags aren't hierarchical
        'parent_item_colon' => null,
        'edit_item' => 'Edit Category',
        'update_item' => 'Update Category',
        'add_new_item' => 'Add Category',
        'new_item_name' => 'Add Category',
        'separate_items_with_commas' => 'Separate Guide/Cheat Categories with commas',
        'add_or_remove_items' => 'Add or remove Guide/Cheat Category',
        'choose_from_most_used' => 'Choose from the most used Categories',
    );

    $wp_taxonomies['portfolio_category']->label = 'Guide/Cheat Categories';
}
add_action( 'init', 'wpa4182_init',999);

我找不到通常注册自定义帖子的主题php代码(hook)的任何部分。所以我设法将固定链接更改为:

`http://www.mamawithabs.com/portfolio/mauris-pulvinar-nisl-nec-auctor/`

到此:

`http://www.mamawithabs.com/guides/mauris-pulvinar-nisl-nec-auctor/`

我在执行重定向时使用了以下代码:

function modify_portfolio() {
global $wp_post_types;
    $rewrite = &$wp_post_types['portfolio']->rewrite;
    $rewrite['slug'] = 'guides';
}
add_action( 'init', 'modify_portfolio', 999 );

它成功地将链接重定向到所需的永久链接格式,但结果为404错误(找不到页面。)。

0 个答案:

没有答案