自定义分类法创建
add_action( 'init', 'ashu_post_type' );
function ashu_post_type() {register_taxonomy('province','post',array('label' => '省','rewrite' => array( 'slug' => 'province' ),'hierarchical' => true));register_taxonomy('city','post',array('label' => '市','rewrite' => array( 'slug' => 'city' ),'hierarchical' => true));register_taxonomy('genre','post',array('label' => '类型','rewrite' => array( 'slug' => 'genre' ),'hierarchical' => true));
}
重写规则和模板设置:在主题文件夹下建立page-sift.php
文件作为筛选页面的模板文件,并添加重写规则等。部分关键代码如下
// 获取筛选页面的Url
function ashuwp_sift_link() {return home_url( "/sift" );
}// 添加query变量
function ashuwp_query_vars( $public_query_vars ) {$public_query_vars[] = 'ashuwp_page';$public_query_vars[] = 'condition';return $public_query_vars;
}// sift页面的重写规则
function ashuwp_rewrite_rules( $wp_rewrite ) {$new_rules = array(&