0

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>
                </div>
                <div class="flexslider carousel">
                    <ul class="slides"> 
                  <?php                         
                      $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)
                  ?>    

                    <li>
                        <div class="slider_contents">
                            <a href="http://www.youtube.com/watch?v=<?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>
                                <div class="excerpt_contents">
                                    <?php echo excerpt('10'); ?>
                                </div>
                                <?php if ( get_field('mp3_link') ) : ?>
                                <div class="download_link">
                                    <a target="_blank" href="<?php echo get_field('mp3_link'); ?>">Get the MP3 >></a>
                                </div>
                                <?php else : ?>
                                <?php endif; ?>
                            </div>
                        </div>
                    </li>     
                    <?php endforeach; ?>
                    </ul>
                </div>                  
            <?php endforeach; ?>
0

Update you code with this

<?php // Output all Taxonomies names with their respective items
        $catCount = 0;
        $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>
            </div>
            <div class="flexslider carousel">
                <ul class="slides"> 
              <?php                         
                  $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)
              ?>    

                <li>
                    <div class="slider_contents">
                        <a href="http://www.youtube.com/watch?v=<?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>
                            <div class="excerpt_contents">
                                <?php echo excerpt('10'); ?>
                            </div>
                            <?php if ( get_field('mp3_link') ) : ?>
                            <div class="download_link">
                                <a target="_blank" href="<?php echo get_field('mp3_link'); ?>">Get the MP3 >></a>
                            </div>
                            <?php else : ?>
                            <?php endif; ?>
                        </div>
                    </div>
                </li>     
                <?php endforeach; ?>
                </ul>
            </div>                  
        <?php 
        $catCount++;
        if($catCount == 2)
        {
            echo '<a href="'.get_term_link($terms{2}->term_id, $term->taxonomy).'">Next</a>';
        }
        endforeach; ?>
| improve this answer | |
  • Its not working. – monirjnu Apr 10 '17 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.