我已经看到了很多几乎答案,但没有确定的答案,所以我在这里。
我正在尝试像http://magazine.pomona.edu那样构建我的 WP 永久链接。该站点的组织形式为http://example.com/%volume_year%/%volume_issue%/%postname%/。示例: http: //magazine.pomona.edu/2012/fall/a-carefully-calculated-caper/
我在找出不提供 404 或 400 的永久链接结构时遇到问题。我创建了两个自定义分类法,“volume_year”和“volume_issue”。我更改了我的永久链接结构以反映这些(/%volume_year%/%volume_issue%/%postname%/)并检查了帖子管理员(2012 年和秋季)中的适当条款。
但是,当我尝试查看该帖子时,该帖子应位于http://example.com/2012/fall/lost-and-found/。我收到 400 Bad Request 错误,我的 URL 是http://example.com/%volume_year%/%volume_issue%/lost-and-found/。显然,占位符没有被转换为术语。我错过了什么,和/或有人有更好的方法吗?
这是我的代码,fwiw:
$labels[0] = array(
'name' => 'Year',
'singular_name' => 'Year',
'menu_name' => 'Year',
'all_items' => 'All Years',
'parent_item' => 'Parent Year',
'parent_item_colon' => 'Parent Year:',
'new_item_name' => 'New Year Name',
'add_new_item' => 'Add New Year',
'edit_item' => 'Edit Year',
'update_item' => 'Update Year',
'separate_items_with_commas' => 'Separate years with commas',
'search_items' => 'Search years',
'add_or_remove_items' => 'Add or remove years',
'choose_from_most_used' => 'Choose from the most used years',
);
$rewrite[0] = array(
'slug' => 'volume_year',
'with_front' => false,
'hierarchical' => true,
);
$args[0] = array(
'labels' => $labels[0],
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => 'volume_year',
'rewrite' => $rewrite[0],
);
register_taxonomy( 'volume_year', array('post'), $args[0] );
$labels[1] = array(
'name' => 'Issue',
'singular_name' => 'Issue',
'menu_name' => 'Issue',
'all_items' => 'All Issues',
'parent_item' => 'Parent Issue',
'parent_item_colon' => 'Parent Issue:',
'new_item_name' => 'New Issue Name',
'add_new_item' => 'Add New Issue',
'edit_item' => 'Edit Issue',
'update_item' => 'Update Issue',
'separate_items_with_commas' => 'Separate issues with commas',
'search_items' => 'Search issues',
'add_or_remove_items' => 'Add or remove issues',
'choose_from_most_used' => 'Choose from the most used issues',
);
$rewrite[1] = array(
'slug' => 'volume_issue',
'with_front' => false,
'hierarchical' => true,
);
$args[1] = array(
'labels' => $labels[1],
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => 'volume_issue',
'rewrite' => $rewrite[1],
);
register_taxonomy( 'volume_issue', array('post'), $args[1] );