我知道WP 3.1增加了对自定义帖子类型存档的支持,但有没有办法为它们定制永久链接?
自定义POST类型档案的自定义固定链接?
2 个回复
最合适的回答,由SO网友:Hameedullah Khan 整理而成
以一个名为movie
下面的代码将创建自定义永久链接awesomemovies/
无论是使用register\\u post\\u类型的has\\u archive和rewrite选项创建的。
add_filter( \'rewrite_rules_array\', \'custom_permalink_for_my_cpt\' );
function custom_permalink_for_my_cpt( $rules ) {
$custom_rules = array();
// for archive urls
$custom_rules[\'awesomemovies/?$\'] = \'index.php?post_type=movie\';
// for individual post urls e.g: http://blog.com/awesomemovies/post-name/
$custom_rules[\'awesomemovies/([^/]+)/?$\'] = \'index.php?post_type=movie&pagename=$matches[1]\';
return $custom_rules + $rules;
}
有关更多信息,请参阅WP_RewriteSO网友:Rev. Voodoo
要自定义CPT存档的永久链接?看看这个http://mark.mcwilliams.me/2010/10/wordpress-3-1-introduces-custom-post-type-archives/
基本上只需使用has\\u归档功能即可更改永久链接
add_action( \'init\', \'mcw_projects_post_type\' );
function mcw_projects_post_type() {
register_post_type( \'projects\', array(
\'labels\' => array(
\'name\' => __(\'Projects\'),
\'singular_name\' => __(\'Project\')
),
\'public\' => true,
\'show_ui\' => true,
\'rewrite\' => array(
\'slug\' => \'project\',
\'with_front\' => false
),
\'has_archive\' => true
) );
}
是注册CPT的一种方法。has\\u归档打开归档支持。将其替换为:\'has_archive\' => \'projects\'
或者您需要为CPT归档调整永久链接什么。或者,您是否正在寻找方法来改变CPT的永久性?这是通过rewrite参数完成的http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
不确定你想做的是哪一部分
结束