pagination for list category posts ( Custom post type )

I have showed the lists of category with posts but how can i add pagination ? For example : i have three category and each category has 4 or 5 posts. I want to show first two category with posts and the third one with the pagination. How can i achieve this ? This is my current code.

Thank you!

        <?php // Output all Taxonomies names with their respective items

            $terms = get_terms('sermon-series');
            foreach( $terms as $term ):
                <div class="sermon_title_area">
                    <h3><?php echo $term->name; // Print the term name ?></h3>   
                    <div class="sermon_date">
                        <p><?php echo $term->description; ?></p>
                <div class="flexslider carousel">
                    <ul class="slides"> 
                      $posts = get_posts(array(
                        'post_type' => 'sermon',
                        'taxonomy' => $term->taxonomy,
                        'term' => $term->slug,                                  
                        'nopaging' => true, // to show all posts in this taxonomy, could also use 'numberposts' => -1 instead
                      foreach($posts as $post): // begin cycle through posts of this taxonmy
                        setup_postdata($post); //set up post data for use in the loop (enables the_title(), etc without specifying a post ID)

                        <div class="slider_contents">
                            <a href="<?php echo get_field('youtube_video_link'); ; ?>" rel="prettyPhoto" title="<?php the_title(); ?>"><?php the_post_thumbnail('slide-image', array('class' => 'slide-thumb')); ?></a>
                            <div class="slider_inside">
                                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                <div class="date">
                                    <?php the_time('F j, Y'); ?>
                                <div class="excerpt_contents">
                                    <?php echo excerpt('10'); ?>
                                <?php if ( get_field('mp3_link') ) : ?>
                                <div class="download_link">
                                    <a target="_blank" href="<?php echo get_field('mp3_link'); ?>">Get the MP3 >></a>
                                <?php else : ?>
                                <?php endif; ?>
                    <?php endforeach; ?>
            <?php endforeach; ?>

Read more here: pagination for list category posts ( Custom post type )

Leave a Reply

Your email address will not be published. Required fields are marked *