英文:
WordPress pagination not working properly
问题
我分析了你的代码并翻译了相关部分:
// 允许的 HTML 标签
$allowed_html = [
"span" => [
"class" => []
],
"a" => [
"class" => [],
"href" => []
]
];
// 页码前后应该出现的内容
$args = [
'before_page_number' => '<span>',
'after_page_number' => '</span>'
];
// 打印分页链接
printf('<nav class="pagination">%s</nav>', wp_kses(paginate_links($args), $allowed_html));
请注意,这段代码是用于分页的,但你提到了一个问题,即在点击链接时,.current 类没有更新。如果需要帮助解决此问题,请提供更多相关信息,我将尽力协助你。
英文:
my pagination code:
function tevent_pagination() {
// Allowed html
$allowed_html = [
"span" => [
"class" => []
],
"a" => [
"class" => [],
"href" => []
]
];
// What should be before the page number
$args = [
'before_page_number' => '<span>',
'after_page_number' => '</span>'
];
// Printing the pagination
printf("<nav class='pagination'>%s</nav>", wp_kses( paginate_links( $args ), $allowed_html ));}
pagination links are correctly displayed, even the content is perfectly display which I click pagination links. but when I click on links the .current class is not updating. I have tried many things but still this issue is not resolving.
答案1
得分: 2
This issue was resolved by writing wp_reset_query() at the top of the function.
英文:
This issue was resolved by writing wp_reset_query() at the top of the function.
答案2
得分: 1
你没有在参数中传递当前页面。
global $wp_query;
$big = 999999999; // 需要一个不太可能的整数
$args = [
'before_page_number' => '<span>',
'after_page_number' => '</span>',
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
];
echo paginate_links($args);
英文:
You are not passing current page on the args.
global $wp_query;
$big = 999999999; // need an unlikely integer
$args = [
'before_page_number' => '<span>',
'after_page_number' => '</span>',
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
];
echo paginate_links($args);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论