无法使用WP_query进行分页

问题描述 投票:0回答:2

试图制作我的第一个wordpress主题,我在页面上使用我的自定义帖子类型进行分页时遇到了麻烦。

我会显示分页链接,但是当我点击分页链接时,我会看到“找不到页面”。

我的代码......

<ul id="og-grid" class="og-grid">
                <?php
                  $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                    $query = new WP_Query(array(
                        'post_type' => 'projects',
                        'post_status' => 'publish',
                        'posts_per_page' => 9,
                        'paged' => $paged
                    ));

                    while ($query->have_posts()) {
                        $query->the_post();
                        $post_id = get_the_ID();
                ?>

                <li>
                    <a href="<?php the_permalink();?>" data-largesrc="<?php echo the_post_thumbnail_url(); ?>" data-title="<?php the_title();  ?>" data-owner="<?php the_field('project-owner') ?>" data-date="<?php the_field('project-date') ?>" data-location="<?php the_field('project-location') ?>" data-contractor="<?php the_field('project-contractor') ?>" data-value="<?php the_field('project-value') ?>" data-description="<?php echo esc_html(get_the_excerpt()); ?>">
                        <div class="project-roll-item" style="background: url('<?php the_post_thumbnail_url(); ?>') no-repeat center center; background-size: cover;">
                            <h4 class="project-info"><?php the_title(); ?></h4>
                        </div>
                    </a>
                </li>

                    <?php
                    } ?>

                </ul>

                <div class="pagination" style="margin-top: 50px;">
                        <?php
                                echo paginate_links( array(
                                        'base'         => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
                                        'total'        => $query->max_num_pages,
                                        'current'      => max( 1, get_query_var( 'paged' ) ),
                                        'format'       => '?paged=%#%',
                                        'show_all'     => false,
                                        'type'         => 'plain',
                                        'end_size'     => 2,
                                        'mid_size'     => 1,
                                        'prev_next'    => true,
                                        'prev_text'    => sprintf( '<i></i> %1$s', __( 'Newer Posts', 'text-domain' ) ),
                                        'next_text'    => sprintf( '%1$s <i></i>', __( 'Older Posts', 'text-domain' ) ),
                                        'add_args'     => false,
                                        'add_fragment' => '',
                                ) );
                        ?>
                </div>

                <?php wp_reset_query(); ?>

有帮助吗?谢谢。

php wordpress
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.