<?classzsjh{functioninit () {add_action (' Init ',Array($this, ' CREATE_ZSJH ') ); Add_filter (' Post_type_link ',Array($this, ' Get_permalink '), 1, 3 ); } functionCreate_zsjh () {$labels=Array( ' Name ' + ' enrollment program ', ' singular_name ' + ' Enrollment program ', ' add_new ' + ' Add Admission program ', ' Ad D_new_item ' + ' adds a new admissions program ', ' Edit_item ' + ' Edit Admissions program ', ' New_item ' + ' New Admissions program ', ' View_item ' = ' view ', ' search_items ' = ' search ', ' not_found ' and ' not yet added to the admissions program Oh ~ ', ' Not_found_in_trash ' + ' has not deleted the admissions program Oh ~ ', ' parent_item_colon ' = ', ' Menu_name ' = ' Admissions program ', ' menu_position ' + 5 ); $args=Array( ' Labels ' =$labels, ' public ' =true, ' publicly_queryable ' =true, ' show_ui ' =true, ' show_in_menu ' =true, ' query_var ' =true, ' capability_type ' = ' post ', ' has_archive ' =true, ' hierarchical ' =false, ' supports ' =Array(' title ', ' editor ', ' thumbnail ', ' comments ', ' custom-fields '), ); //Customizing a HC_POST_TYPE_ZSJH article typeRegister_post_type (' Hc_post_type_zsjh ',$args); //Customizing fixed-link rulesAdd_action (' Generate_rewrite_rules ',Array($this, ' Jihua_rewrite_rules ') ); } functionJihua_rewrite_rules ($WP _rewrite ) { Global $WP _rewrite; $WP _rewrite->add_permastruct (' Hc_post_type_zsjh ', '/jihua/%jihua_id%.html ',false); $new _rules=Array(' jihua/([0-9]+)?. html$ ' = ' index.php?post_type=hc_post_type_zsjh&p= $matches [1] ' ); $WP _rewrite->rules =$new _rules+$WP _rewrite-rules; } functionGet_permalink ($permalink,$post,$leavename ) { //replace%jihua_id% with the current article ID $permalink=Str_replace("%jihua_id%",$post->id,$permalink); return $permalink; }}$ZSJH=NewZSJH ();$ZSJH-init ();?>
Bill: WordPress Custom Post_type, and custom permalink