Home >Backend Development >PHP Tutorial >WordPress article list pagination is static, adding html suffix

WordPress article list pagination is static, adding html suffix

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-08-08 09:20:591206browse

See the effect first

After use, the link address is: http://localhost/news/paged/1.html

1. Add a filter and use the link address to add the .html suffix

add_filter( 'get_pagenum_link' ,'my_get_pagenum_link' ,1 ,1 );

function my_get_pagenum_link( $url )
{
        return str_replace('.html', '', $url).'.html';
}

2. Add repeat Write rules

if( !is_admin() ) //Only front-end page application

  add_action('init'   , 'my_post_rewrite' );


function my_ post_rewrite()

{

global $wp_rewrite;

add_rewrite_rule('news/paged/(.*)?.html$' , 'index.php?p=news&page=$matches[2]','top' ); //Only for The activation function of category slug is 'news'

add_rewrite_rule('(.*)?/paged/(.*)?.html$' , 'index.php?p=$matches[1]&page=$matches[2 ]','top' ); //Applies to all categories

}

Note: The expression may change according to your actual situation

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the static pagination of WordPress article list, adding the html suffix, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Mysqli basicsNext article:Mysqli basics