How to implement the wordpress routing function

Source: Internet
Author: User
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 have custom url parameters, you must use the wordpress function to add the parameters to add: add & nbsp; query_argsfunction & nbsp; add_query_vars ($ aV implements the wordpress routing function
After two days of regular expression learning and studying wordpress routing functions, the custom 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_args
Function add_query_vars ($ aVars ){
$ AVars [] = 'score ';
$ AVars [] = 'type'; // represents the name of the product category as shown in the URL
Return $ 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-sort by time and other latest entries
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-type
Add_rewrite_rule ('^ text /? (/Page/([0-9] + )?)? /? $ ', 'Index. php? Cat = 2 & paged = $ matches [2] ', 'top'); // Category ID corresponding to the http://www.ke6.com/text/ field sub
Add_rewrite_rule ('^ image /? (/Page/([0-9] + )?)? /? $ ', 'Index. php? Cat = 3 & paged = $ matches [2] ', 'top'); // Category ID corresponding to the http://www.ke6.com/image/ profile
Add_rewrite_rule ('^ video /? (/Page/([0-9] + )?)? /? $ ', 'Index. php? Cat = 4 & paged = $ matches [2] ', 'top'); // Category ID corresponding to the http://www.ke6.com/video/ Video
Add_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/

------ Solution --------------------
I don't know what you are doing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.