php - 在分页中使用时如何从 WP_Query url 中删除帖子名称?
问题描述
这可能吗?
我正在尝试在我的页面和单页上进行分页。看起来它正在工作,因为它可以识别有多少页面并显示 URL。问题:网址错误!
函数.php:
function pagination_bar( $query_wp )
{
$pages = $query_wp->max_num_pages;
$big = 999999999; // need an unlikely integer
if ($pages > 1)
{
$page_current = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $page_current,
'total' => $pages,
));
}
}
查询:
$the_query = new WP_Query( array( 'posts_per_page' => 25,
'paged' => $paged
) );
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
的HTML:
<nav class="pagination">
<?php pagination_bar( $the_query ); ?>
激活分页并单击下一页时我得到的 URL:
我想得到什么:
问题:(如何)我可以这样做吗?
编辑: 我也尝试像这样编辑它
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( "https://mywebsitename.com%_%" ) ) ),
但它只给了我我的URL
,没有/page/x
...
解决方案
好吧。我通过改变这样的基础让它工作:
从:
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
至:
'base' => str_replace( $big, '%#%', "http://example.com/page/$big" ),
推荐阅读
- docker - 通过弹性 beanstalk 部署 Docker 容器的问题:basex 9.3.1
- json - 如何将 Future http 函数返回为布尔值,以便根据 http 响应的结果将其用于进一步的活动流
- python - 从具有多列条件的数据框中获取行
- android - 如何在 android studios 中向现有链添加视图
- javascript - 为什么我不能在我的快速路由中使用中间件?
- angular - Algolia&Angular : NullInjectorError: No provider for NgAisInstantSearch
- java - 字符串对象和存储
- forms - 访问表达式问题
- r - 更改 R 对其值进行排序的方式
- laravel - 在 Laravel 中使用 JQuery 创建可排序表