简体   繁体   中英

How to add pagination in a Wordpress Custom Post Type Query

I have the code below but pagination not working:

<?php 
/*
Template Name: Service Page
*/
get_header();?>

<!-- service Section -->
<section id="practice-wrap1" class="section-gray">
<div class="container-fluid">
<div class="row text-center">
<?php
$query = new WP_Query(array('post_type'=>'service-items', 'posts_per_page' => 4, 'page'=> $paged, 'order' => 'DESC'));
?>
<?php if ($query->have_posts() ) : while ($query->have_posts() ) : $query->the_post(); ?>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="service-item">
<div class="service-item-img">
<?php the_post_thumbnail('service-items', array('class' => 'post-thumb')); ?>
<div class="overlay-one transition4s"></div>
</div>
<div class="service-content">
<div class="service-icon">
<span><i class="fa fa-globe"></i></span>
</div>
<h3 class="title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
<p class="description"><?php echo word_count(get_the_excerpt(), '20'); ?>   </p>
<a href="<?php the_permalink();?>" class="read-more fa fa-plus"></a>
</div>
</div>
</div>
<?php endwhile; ?>
<?php echo paginate_links();?>
<?php else:?>
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>

</div>
</section>

<?php get_footer();?>

I am trying to use paginate_links Wordpress function but no matter where I put it, I can't make it work. Can someone help me with this?

请检查以下链接,希望这能使您满意:

  https://stackoverflow.com/questions/41738362/how-to-include-pagination-in-a-wordpress-custom-post-type-query?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

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