After two days of regular expression learning and studying the wordpress routing function, the wordpress routing function is successfully implemented. The following describes the implementation of routing rules.
If you want to pass custom url parameters through a route, you must use the wordpress function to add the parameters:
// Add query_argsfunction add_query_vars ($ aVars) {$ aVars [] = 'score '; $ aVars [] = 'type '; // represents the name of the product category as shown in the URLreturn $ aVars;} add_filter ('query _ VARs', 'Add _ query_vars'); // wordpress filter
You also need to use the wordpress function to obtain the parameters on the page:
$type=isset($wp_query->query_vars['type'])?urldecode($wp_query->query_vars['type']):'';
// Routing rules-function add_rewrite_rules ($ aRules) {$ aNewRules = array ('text/([^ latest] [^/] +) /? (/Page/([0-9] + )?)? /? $ '=> 'Index. php? Cat = 2 & score = $ matches [1] & paged = $ matches [3] ', 'image/([^ latest] [^/] + )/? (/Page/([0-9] + )?)? /? $ '=> 'Index. php? Cat = 3 & score = $ matches [1] & paged = $ matches [3] ', 'Video/([^ latest] [^/] + )/? (/Page/([0-9] + )?)? /? $ '=> 'Index. php? Cat = 4 & score = $ matches [1] & paged = $ matches [3] ', 'resource/([^ latest] [^/] + )/? (/Page/([0-9] + )?)? /? $ '=> 'Index. php? Cat = 5 & score = $ matches [1] & paged = $ matches [3] ', 'text/(latest )/? (/Page/([0-9] + )?)? /? $ '=> 'Index. php? Cat = 2 & type = $ matches [1] & paged = $ matches [3] ', 'image/(latest )/? (/Page/([0-9] + )?)? /? $ '=> 'Index. php? Cat = 3 & type = $ matches [1] & paged = $ matches [3] ', 'Video/(latest )/? (/Page/([0-9] + )?)? /? $ '=> 'Index. php? Cat = 4 & type = $ matches [1] & paged = $ matches [3] ', 'resource/(latest )/? $ '=> 'Index. php? Cat = 5 & type = $ matches [1] ',' (month )/? (/Page/([0-9] + )?)? /? $ '=> 'Index. php? Score = $ matches [1] & paged = $ matches [3] ',' (24hr )/? (/Page/([0-9] + )?)? /? $ '=> 'Index. php? Score = $ matches [1] & paged = $ matches [3] ',); $ aRules = $ aNewRules + $ aRules; return $ aRules ;} add_filter ('rewrite _ rules_array ', 'Add _ rewrite_rules ');
// Routing rule-category add_rewrite_rule ('^ text /? (/Page/([0-9] + )?)? /? $ ', 'Index. php? Cat = 2 & paged = $ matches [2] ', 'top'); // category IDadd_rewrite_rule (' ^ image /? (/Page/([0-9] + )?)? /? $ ', 'Index. php? Cat = 3 & paged = $ matches [2] ', 'top'); // category IDadd_rewrite_rule (' ^ video /? (/Page/([0-9] + )?)? /? $ ', 'Index. php? Cat = 4 & paged = $ matches [2] ', 'top'); // category of the http://www.ke6.com/video/ video IDadd_rewrite_rule (' ^ resource /? (/Page/([0-9] + )?)? /? $ ', 'Index. php? Cat = 5 & paged = $ matches [2] ', 'top'); // Category ID corresponding to the http://www.ke6.com/resource/ Video
The url routing effect is as follows:
All-24 hours: http://www.domain.com/24hr/
All-7: http://www.domain.com/
All-30 days: http://www.domain.com/month/
24 hours: http://www.domain.com/text/24hr/
Paragraph-7 days: http://www.domain.com/text/
Paragraph-30 days: http://www.domain.com/text/month/
Video: video
Interesting image: image
Dry Goods: resource
Random: random
Freshest-all: http://www.domain.com/latest/
Freshest-paragraph: http://www.domain.com/text/latest/
Link: http://www.tantengvip.com/2013/11/wordpress-route/
For more information about wordpress secondary development, visit:
Http://www.tantengvip.com/category/web/wordpress/
Reply to discussion (solution)
Reply to score !!
I don't know what you are doing
I don't know what you are doing
Publish technical posts and share them!