


Code example of wordpress custom url parameters to implement routing function_PHP tutorial
After two days of learning regular expressions and studying the routing function of WordPress, I successfully implemented the custom WordPress routing function. The following is the implementation of routing rules.
If there are custom url parameters, to be passed through routing, the parameters must be added through the wordpress function:
//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
At the same time, 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 - sorting based on time and the latest entries in each category
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 Rules - Category
add_rewrite_rule('^text/?(/ page/([0-9]+)?)?/?$','index.php?cat=2&paged=$matches[2]','top'); //Corresponding category ID
add_rewrite_rule( '^image/?(/page/([0-9]+)?)?/?$','index.php?cat=3&paged=$matches[2]','top');
add_rewrite_rule ('^video/?(/page/([0-9]+)?)?/?$','index.php?cat=4&paged=$matches[2]','top');
add_rewrite_rule('^resource/?(/page/([0-9]+)?)?/?$','index.php?cat=5&paged=$matches[2]','top');

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP and Flutter are popular technologies for mobile development. Flutter excels in cross-platform capabilities, performance and user interface, and is suitable for applications that require high performance, cross-platform and customized UI. PHP is suitable for server-side applications with lower performance and not cross-platform.

WordPress posts are stored in the /wp-content/uploads folder. This folder uses subfolders to categorize different types of uploads, including articles organized by year, month, and article ID. Article files are stored in plain text format (.txt), and the filename usually includes its ID and title.

WordPress template files are located in the /wp-content/themes/[theme name]/ directory. They are used to determine the appearance and functionality of the website, including header (header.php), footer (footer.php), main template (index.php), single article (single.php), page (page.php), Archive (archive.php), category (category.php), tag (tag.php), search (search.php) and 404 error page (404.php). By editing and modifying these files, you can customize the appearance of your WordPress website

C++ parameter type safety checking ensures that functions only accept values of expected types through compile-time checks, run-time checks, and static assertions, preventing unexpected behavior and program crashes: Compile-time type checking: The compiler checks type compatibility. Runtime type checking: Use dynamic_cast to check type compatibility, and throw an exception if there is no match. Static assertion: Assert type conditions at compile time.

Golang regular expressions use the pipe character | to match multiple words or strings, separating each option as a logical OR expression. For example: matches "fox" or "dog": fox|dog matches "quick", "brown" or "lazy": (quick|brown|lazy) matches "Go", "Python" or "Java": Go|Python |Java matches words or 4-digit zip codes: ([a-zA

The most stable WordPress version is the latest version because it contains the latest security patches, performance enhancements, and introduces new features and improvements. In order to update to the latest version, log into your WordPress dashboard, go to the Updates page and click Update Now.

WordPress requires registration. According to my country's "Internet Security Management Measures", websites that provide Internet information services within the country must register with the local provincial Internet Information Office, including WordPress. The registration process includes steps such as selecting a service provider, preparing information, submitting an application, reviewing and publishing, and obtaining a registration number. The benefits of filing include legal compliance, improving credibility, meeting access requirements, ensuring normal access, etc. The filing information must be true and valid, and must be updated regularly after filing.

Since the launch of ChatGLM-6B on March 14, 2023, the GLM series models have received widespread attention and recognition. Especially after ChatGLM3-6B was open sourced, developers are full of expectations for the fourth-generation model launched by Zhipu AI. This expectation has finally been fully satisfied with the release of GLM-4-9B. The birth of GLM-4-9B In order to give small models (10B and below) more powerful capabilities, the GLM technical team launched this new fourth-generation GLM series open source model: GLM-4-9B after nearly half a year of exploration. This model greatly compresses the model size while ensuring accuracy, and has faster inference speed and higher efficiency. The GLM technical team’s exploration has not
