wordpress - 将分页添加到 WordPress 类别查询

标签 wordpress pagination

我正在尝试使用 WordPress 将分页添加到网站库的自定义类别列表中。我尝试遵循一些指南,但无法将分页功能添加到我的查询中。我已经添加了我当前的查询。 任何帮助将不胜感激。

<?php

            global $paged;
            $curpage = $page ? $paged :1;

            $args2 = array(
                'taxonomy' => 'media-category',
                //'parent' => '5',
                'child_of' => 7,
                'orderby' => 'date',
                'order' => 'ASC',
                'hide_empty' => 0,
                'number' => 99,
                'posts_per_page' => 3,
                'paged' => $paged,
            );
            ?>
            <ul class="gallery-list small-block-grid-1 medium-block-grid-2 large-block-grid-3">
                <?php
                $categories = get_categories($args2);
                foreach ($categories as $category) {

                    $args = array(
                        'post_type' => 'attachment',
                        'post_status' => 'any',
                        'posts_per_archive_page' => -1,
                        'tax_query' => array(
                            array(
                                'taxonomy' => 'media-category',
                                'field' => 'slug',
                                'terms' => array($category->name, 'featured'),
                                'operator' => 'AND',
                            ),
                        ),
                    );
                    $custom_query = new WP_Query($args);
                    ?>
                    <?php while ($custom_query->have_posts()) : $custom_query->the_post(); ?>

最佳答案

我找到了答案。

// Sets manual pagination
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $posts_per_page = 12;
            $offset = ($posts_per_page * $paged) - 12 ;

$args = array(
                'orderby' => 'id',
                'order' => 'DESC',
                'hide_empty' => 0,
                'number' => $posts_per_page,
                'offset' => $offset,
            );

$categories = get_terms($taxonomies, $args);

这会将页面设置为每页 12 个项目并偏移页码。

关于wordpress - 将分页添加到 WordPress 类别查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21193676/

相关文章:

pagination - material-table 和 reactjs 中自定义分页的任何示例

html - IE 和 Firefox 中的 CSS 绝对定位问题,但 Chrome 中没有 - Wordpress 模板

html - 如何在 WordPress 中正确设置 margin-top?

mysql - Wordpress - 数据库迁移导致 Accordion 插件内容重置/消失

android - "FBReader"如何在epub中对html文件进行分页

grails - 我想在条件返回值中添加分页

php - 其他页面发生使用fnClearTable分页跳转到重绘表第一页

java - 如何实现服务器端分页结果不可预测

javascript - jQuery 不影响正确的项目

php - 根据订单详情页面中的产品标题替换产品 SKU