Wordpress 分页有时无法加载/显示 [英] Wordpress pagination sometimes doesn't load/show

查看:31
本文介绍了Wordpress 分页有时无法加载/显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为此找到解决方案,但我在网上找不到任何东西,而且我自己也无法弄清楚.

I tried to find soulution for this, but I can't find anything online and I can't figure it out by myself.

所以,问题是,有时本机分页有效,有时无效.我尝试使用不同的主题,停用插件,但问题保持不变.我将 the_posts_pagination() 函数与原生 WP 循环一起使用,因此没有自定义查询.

So, the problem is, that sometimes native pagination works, sometimes doesn't. I tried to use different themes, deactivate the plugins, but problem stays the same. I use the_posts_pagination() function with native WP loop, so there's no custom queries.

如果您有任何建议,我将不胜感激.谢谢!

I would appreciate any advice you guys have. Thank you!

这是发生了什么的屏幕截图:

This is a screenshot of what happens:

推荐答案

您可以使用 pagination_links() 而不是 the_posts_pagination() 来使用自定义分页.让函数为 wp103033_pagination()然后在您的 functions.php 文件中添加函数 -

You can use a custom pagination using paginate_links() instead of the_posts_pagination(). Let the function is wp103033_pagination() Then in your functions.php file add the function -

function wp103033_pagination($args = array(), $class = 'pagination') {
    if ($GLOBALS['wp_query']->max_num_pages <= 1) {
        return;
    }
    $args = wp_parse_args(
        $args,
        array(
            'mid_size' => 2,
            'prev_next' => TRUE,
            'prev_text' => __('PREV', 'text-domain'),
            'next_text' => __('NEXT>', 'text-domain'),
            'screen_reader_text' => __('Posts navigation', 'text-domain'),
            'type' => 'array',
            'current' => max(1, get_query_var('paged')),
        )
    );
    $links = paginate_links($args); ?>

    <nav aria-label="<?php echo $args['screen_reader_text']; ?>">
        <ul class="pagination">
            <?php foreach ($links as $key => $link) { ?>
                <li class="page-item <?php echo strpos($link, 'current') ? 'active' : ''; ?>">
                    <?php echo str_replace('page-numbers', 'page-link', $link); ?>
                </li>
            <?php } ?>
        </ul>
    </nav>
<?php }

这篇关于Wordpress 分页有时无法加载/显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆