php - Pagination not displaying

I'm using HTML5Blank theme to edit my own theme on clean basis, and trying to set the pagination but it's not

I'm using HTML5Blank theme to edit my own theme on clean basis, and trying to set the pagination but it's not displaying for some reason, and I cant find out why.

Index.php calls loop then pagination templates

<section>
    <?php get_template_part('loop'); ?>

    <?php get_template_part('pagination'); ?>
</section>

Pagination.php calls pagination function

<div class="pagination">
    <?php html5wp_pagination(); ?>
</div>

The function is

// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and  Previous Links, No plugin
function html5wp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
    'base' => str_replace($big, '%#%', get_pagenum_link($big)),
    'format' => '?paged=%#%',
    'current' => max(1, get_query_var('paged')),
    'total' => $wp_query->max_num_pages
));
}

I haven't touched anything related to the pagination, and I can see that the <div class="pagination"> is called in the HTML using Chrome console, but is not displaying anything.

I thought this could be because I had not enough post to display the pagination, but I tried to add a lot of posts, and it's still not showing.

Any idea of what is the problem ?

I'm using HTML5Blank theme to edit my own theme on clean basis, and trying to set the pagination but it's not displaying for some reason, and I cant find out why.

Index.php calls loop then pagination templates

<section>
    <?php get_template_part('loop'); ?>

    <?php get_template_part('pagination'); ?>
</section>

Pagination.php calls pagination function

<div class="pagination">
    <?php html5wp_pagination(); ?>
</div>

The function is

// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and  Previous Links, No plugin
function html5wp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
    'base' => str_replace($big, '%#%', get_pagenum_link($big)),
    'format' => '?paged=%#%',
    'current' => max(1, get_query_var('paged')),
    'total' => $wp_query->max_num_pages
));
}

I haven't touched anything related to the pagination, and I can see that the <div class="pagination"> is called in the HTML using Chrome console, but is not displaying anything.

I thought this could be because I had not enough post to display the pagination, but I tried to add a lot of posts, and it's still not showing.

Any idea of what is the problem ?

Share Improve this question asked Nov 10, 2015 at 11:30 jakzyjakzy 1 2
  • Are you sure you have more posts than the "Blog pages show at most" setting under Settings > Reading? – TheDeadMedic Commented Nov 10, 2015 at 11:46
  • Do echo $wp_query->max_num_pages; in your template and check what it returns – Pieter Goosen Commented Nov 10, 2015 at 12:07
Add a comment  | 

1 Answer 1

Reset to default -1

You need to add your query variable to the global used on the function, in that case "$wp_query", just like that:

<?php
  $yourQuery_args = ['posts_per_page' => '7',];
  $yourQuery = new WP_Query( $yourQuery_args );

  $wp_query = $yourQuery;
  get_template_part('pagination'); 
?>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745300903a4621428.html

相关推荐

  • php - Pagination not displaying

    I'm using HTML5Blank theme to edit my own theme on clean basis, and trying to set the pagination but it's not

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信