我有点难以让定制的permalink for custom post type(CPT)归档正常工作。
我已注册我的“press\\u release”CPT,如下所示:
add_action(\'init\', \'press_release_post_type_init\');
function press_release_post_type_init() {
$labels = array(
\'name\' => _x(\'Press Releases\', \'post type general name\'),
\'singular_name\' => _x(\'Press Release\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'Press Release\'),
\'add_new_item\' => __(\'Add New Press Release\'),
\'edit_item\' => __(\'Edit Press Release\'),
\'new_item\' => __(\'New Press Release\'),
\'view_item\' => __(\'View Press Release\'),
\'search_items\' => __(\'Search Press Releases\'),
\'not_found\' => __(\'No press release found\'),
\'not_found_in_trash\' => __(\'No press release found in Trash\'),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'has_archive\' => \'press-release\',
\'rewrite\' => array(\'slug\' => \'press-release/%year%/%postname%\',\'with_front\' => false),
\'query_var\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'show_in_nav_menus\' => false,
\'menu_position\' => 20,
\'supports\' => array(
\'title\',
\'editor\',
\'author\',
\'revisions\'
)
);
register_post_type(\'press_release\', $args);
}
现在如果我转到URL
http://mysite.press-release
然后我到了
archive-press_release.php
模板,这是正确的。
但是,我希望我的CPT存档永久链接是以下类型press-release/%year%
我在注册CPT时尝试指定上述永久链接结构:
\'has_archive\' => \'press-release/%year%\'
然而,当我去
http://mysite.press-release
或
http://mysite.press-release/2011
在这两种情况下,我都被重定向到
index.php
模板不是存档模板。
要让WordPress明白这一点,我需要添加什么press-release/%year%
带有可选年份部分的permalink实际上是归档模板吗?
我真的很感激任何帮助!我希望这是可能的。
我计划在archive-press_release.php
获取正确年份的记录。
非常感谢,Dasha