admin管理员组文章数量:1122832
I have implemented pagination to my wp site and pagination works correctly, but when I limit to display lets say 10 posts and I have 9 then it won't show pagination.
Is it possible to show in that case 1?
I read that paginate_links will return void if under 2, but is that somehow changeable? (string|array|void) String of page links or array of page links, depending on 'type' argument. Void if total number of pages is less than 2.
My code currently. It shows pages 1 and 2 when posts > 10, but won't show 1 if posts < 10:
global $wp_query;
$args_pagination = array(
'base' => add_query_arg('paged', '%#%'),
'total' => $wp_query->max_num_pages,
'current' => $paged,
'prev_next' => false);
$html .= paginate_links($args_pagination);
Edit: This all function is used as shortcode to use custom pagination in random places of my site (Not random, but not in the place pagination usually is). I used query_posts for that as I honestly don't know that much about wp developement.
extract(shortcode_atts(array('limit' => 1000, 'type' => 'post'), $atts ));
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
query_posts(array(
'posts_per_page' => $limit,
'post_type' => $type,
'order' => 'DESC',
'orderby' =>'date',
'paged' => $paged));
global $wp_query;
$args_pagination = array(
'base' => add_query_arg('paged', '%#%'),
'total' => $wp_query->max_num_pages,
'current' => $paged,
'prev_next' => false);
$html .= paginate_links($args_pagination);
And I returned html to display it on my pre-designed box.
I have implemented pagination to my wp site and pagination works correctly, but when I limit to display lets say 10 posts and I have 9 then it won't show pagination.
Is it possible to show in that case 1?
I read that paginate_links will return void if under 2, but is that somehow changeable? (string|array|void) String of page links or array of page links, depending on 'type' argument. Void if total number of pages is less than 2.
My code currently. It shows pages 1 and 2 when posts > 10, but won't show 1 if posts < 10:
global $wp_query;
$args_pagination = array(
'base' => add_query_arg('paged', '%#%'),
'total' => $wp_query->max_num_pages,
'current' => $paged,
'prev_next' => false);
$html .= paginate_links($args_pagination);
Edit: This all function is used as shortcode to use custom pagination in random places of my site (Not random, but not in the place pagination usually is). I used query_posts for that as I honestly don't know that much about wp developement.
extract(shortcode_atts(array('limit' => 1000, 'type' => 'post'), $atts ));
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
query_posts(array(
'posts_per_page' => $limit,
'post_type' => $type,
'order' => 'DESC',
'orderby' =>'date',
'paged' => $paged));
global $wp_query;
$args_pagination = array(
'base' => add_query_arg('paged', '%#%'),
'total' => $wp_query->max_num_pages,
'current' => $paged,
'prev_next' => false);
$html .= paginate_links($args_pagination);
And I returned html to display it on my pre-designed box.
Share Improve this question edited Jul 7, 2020 at 6:58 Kertix asked Jul 6, 2020 at 15:00 KertixKertix 34 bronze badges 9 | Show 4 more comments1 Answer
Reset to default 1It's not possible. paginate_links()
is hard-coded to stop producing output as soon as it notices that there'll be less than 2 pages. You can see this on lines 4130–4132 of the function's source code here: https://developer.wordpress.org/reference/functions/paginate_links/#source
The only workaround would be to copy the code of paginate_links()
into your own new function and change the 2
to 1
on what is line 4130 for the existing function.
本文标签: paginate linksShow number of pagination pages even when total under two
版权声明:本文标题:paginate links - Show number of pagination pages even when total under two 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308708a1933759.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$wp_query
global? Have you done the unthinkable and usedquery_posts
and now need custom pagination to fix things? Why is this being returned as a string instead of output directly? In order to find a solution we're going to need to know the surrounding context that explains the need for the function and where the values come from for the function call and its arg. Use the edit link under the question tags to add as much information as you can, the key information might even be something you consider obvious or irrelevant, oversharing is good – Tom J Nowell ♦ Commented Jul 6, 2020 at 16:36