简体   繁体   中英

Pagination for custom post type on custom page template in Wordpress

I would like to display for custom post type in a custom page template. I added the code for pagination links. But nothing happens. I referred the parent theme also. Can anyone identify the problem . Thanks in advance

Code:

<?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');
?>
...
$custom_query = new WP_Query($args);
...
$GLOBALS['wp_query'] = $custom_query;
the_posts_pagination();
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM