admin管理员组文章数量:1122832
I want to modify the output of wp_link_pages
.
Basically what I need is to show Previous and Next buttons and current page/total number of pages. I created the Previous and Next button. Now in between them I want to add a current page and the total pages number.
Here is my code
wp_link_pages( array(
'before' => '<div class="page-links">' . __(''),
'after' => '</div>',
'next_or_number' => 'next',
'nextpagelink' => __('Next'),
'previouspagelink' => __('Previous'),
'pagelink' => '%',
'echo' => 1,
) );
I am not sure what to do. The effect I want to get is just like below image.
I want to modify the output of wp_link_pages
.
Basically what I need is to show Previous and Next buttons and current page/total number of pages. I created the Previous and Next button. Now in between them I want to add a current page and the total pages number.
Here is my code
wp_link_pages( array(
'before' => '<div class="page-links">' . __(''),
'after' => '</div>',
'next_or_number' => 'next',
'nextpagelink' => __('Next'),
'previouspagelink' => __('Previous'),
'pagelink' => '%',
'echo' => 1,
) );
I am not sure what to do. The effect I want to get is just like below image.
Share Improve this question edited Feb 5, 2019 at 7:41 phatskat 3,1741 gold badge18 silver badges26 bronze badges asked Feb 5, 2019 at 3:48 Anita DesaiAnita Desai 11 silver badge1 bronze badge 1- if you want to go a plugin route you may have luck with this plugin, it's been actively updated for years and years and is very solid - en-ca.wordpress.org/plugins/wp-pagenavi – NickFMC Commented Feb 5, 2019 at 4:22
2 Answers
Reset to default 0You are using the wrong function, please check this link https://codex.wordpress.org/Function_Reference/paginate_links
As you can see your code should be
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'next_text' => '<i class="fa fa-angle-right"></i>',
'prev_text' => '<i class="fa fa-angle-left"></i>'
) );
if you are using a custom query with WP_Query() your code should be similar to:
$query_post = new WP_Query(array(
...
'paged' => get_query_var('paged'),
...
));
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $query_post->max_num_pages,
'next_text' => '<i class="fa fa-angle-right"></i>',
'prev_text' => '<i class="fa fa-angle-left"></i>'
) );
+1 for Arturo's answer (I don't have enough rep to vote). I just used his solution on a project.
Here are some style rules to pretty it up a bit. This was with Elementor on Twenty-Twenty, so YMMV. Note that I added a div with the class name of custom-pagination-container
around the pagination
div.
<style>
.custom-pagination-container {
display: flex;
}
.pagination {
flex-grow: 1;
flex-shrink: 1;
justify-content: center;
order: 1;
font-size: 15px;
}
.pagination a,
.pagination .current {
margin: 0;
}
.pagination a:hover {
background: none;
}
.pagination .next,
.pagination a,
.pagination .prev,
.pagination span {
display: inline-block;
float: none;
}
.pagination .dots {
vertical-align: sub;
margin-bottom: 0;
}
本文标签: theme developmentHow to Show Nextpreviousand Page Numbers with wplinkpages
版权声明:本文标题:theme development - How to Show Next, Previous, and Page Numbers with wp_link_pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281401a1926306.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论