在Wordpress中自定义页面模板上的自定义帖子类型的分页

时间:2016-07-05 14:49:06

标签: php wordpress pagination

我想在自定义页面模板中显示自定义帖子类型。我添加了分页链接的代码。但没有任何反应。我也提到了父主题。任何人都可以识别问题。提前致谢

代码:

<?php
/* Template Name: events */
get_header('snow');
?>
<div class="main">
    <div class="shop_top">
        <div class="container">
            <div class="col-md-12">
                <h3 class="m_2">Events</h3>
                <ul class="team_list">
                    <?php
                    $args = array('category_name' => 'events');
                    $the_query = new WP_Query($args);
                    if ($the_query->have_posts()) {
                        while ($the_query->have_posts()) {
                            $the_query->the_post();
                            ?>

                            <li><p><?php the_time('l, F jS, Y') ?></p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><p><?php the_content(); ?></p>
                                <a href="<?php the_permalink(); ?>" style="color:#00BFF0;font-size: 12px;text-transform: capitalize;">Read More</a>
                            </li>
                            <?php
                            $eventPlace = get_field('location');
                            if (!empty($eventPlace)) {
                                ?>
                                <li><p style="padding-bottom: 20px;"><b>Place:</b><?= the_field('location'); ?></p></li>

                                <?php
                            }
                        }
                        echo the_posts_pagination(array(
                            'prev_text' => __('Previous page', 'twentysixteen'),
                            'next_text' => __('Next page', 'twentysixteen'),
                            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __('Page', 'twentysixteen') . ' </span>',
                        ));
                    }
                    ?>
                    <?php
                    wp_reset_postdata();
                    ?>
                </ul>
            </div>
        </div>  
    </div>
</div>
<?php
get_footer('snow');
?>

1 个答案:

答案 0 :(得分:0)

...
$custom_query = new WP_Query($args);
...
$GLOBALS['wp_query'] = $custom_query;
the_posts_pagination();
...