WordPress如何添加创建自定义文章类型怎么设置伪静态添加.html
代码如下
function custom_movie_link( $link, $post = 0 ){
if ( $post->post_type == 'movie' ){
return home_url( 'movie/' . $post->ID .'.html' );
} else {
return $link;
}
}
add_filter('post_type_link', 'custom_movie_link', 1, 3);
function movie_rewrites_init(){
add_rewrite_rule(
'movie/([0-9]+)?.html$',
'index.php?post_type=movie&p=$matches[1]',
'top' );
add_rewrite_rule(
'movie/([0-9]+)?.html/comment-page-([0-9]{1,})$',
'index.php?post_type=movie&p=$matches[1]&cpage=$matches[2]',
'top'
);
}
add_action( 'init', 'movie_rewrites_init' );