如何在Wordpress分页中启用.html [英] How enable .html in wordpress pagination
问题描述
我必须使用带有.html扩展名的wordpress,并且我正在使用插件在URL末尾添加.html扩展名,这很好,但是我的分页失败了,它使URL成为/page-url.html/page/2
并出现在页面上找不到,如何在分页中启用.html
?
I have to use wordpress with .html extension, and i am using plugin to make .html extension at end of URL, that is working fine, but my pagination becoming failed, it makes URL as /page-url.html/page/2
that goes on Page not found, how can I enable .html
in pagination ?
谢谢.
顺便说一句,我做了一些类似
By the way, i did some work like
add_filter('get_pagenum_link', function($url) {
$html = strrpos( $url, '.html' );
if( $html > 0 ){
$base_link = substr( $url, 0, strrpos( $url, '/page' ) );
$page_number = basename($url);
$new_url = $base_link.'/?iter='.$page_number;
return $new_url;
}
else{
return $url;
}
});
但是我怎样才能告诉wordpress分页的页面链接应该遵循此?我的意思是分页的主动和非主动链接
but how can i tell wordpress the page link of pagination should follow this ? i mean active and inactive links of pagination
推荐答案
我已经通过添加用于分页URL的过滤器来完成此任务,并且它在.html扩展名下正常工作.以下是使用.html扩展名运行分页的代码.
I have done this task by adding filter for URL of pagination, and it works fine with .html extension. Following is code to run pagination with .html extension.
add_filter('get_pagenum_link', function($url) {
$current_url_arr = explode("?", $_SERVER['REQUEST_URI']);
$current_url = $current_url_arr[0];
$html = strrpos( $url, '.html' );
$page_number = 1;
//$page_number = $_GET['iter'] + 1;
if( $html > 0 ){
$basename = basename($url);
$page_number = substr( $basename, 0, strrpos( $basename , '?') );
$new_url = $current_url.'/?iter='.$page_number;
return $new_url;
}
else{
return $url;
}
});
在查询参数上方,编写以下代码
and on above the query parameter, write the following code
if( $_GET['iter'] > 0 ){
$paged = $_GET['iter'];
}
享受!!!
这篇关于如何在Wordpress分页中启用.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!