• I want to make a template page for displaying taxonomies as template. posts shown in the first page repeated on the next page and so on.

    Please let me know how to make the loop continue in the next page and don’t repeat the same posts.

    The template page: blog.php

    <?php
    
    /*
     Template Name: Blog
    */
    
    get_header(); ?>
    
        <div id="page-content">
    
            <?php $blog_query = new WP_Query( 'showposts:-1' ); ?>
            <?php if ( $blog_query->have_posts() ) : while ( $blog_query->have_posts() ): $blog_query->the_post(); ?>
    
            <article id="post-<?php the_ID(); ?>" <?php post_class( 'article categories' ); ?>>
    
                <?php // Starting content ?>
                <div class="content-section">
                    <h2 class="content-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                </div><!-- content-section -->
    
            </article><!-- article -->
    
        <?php endwhile; ?>
    
        <?php else : ?>
    
            <?php _e( 'Sorry, no posts matched your criteria.', $text_domain ); ?>
    
        <?php endif; ?>
    
        <?php v_pagination( $blog_query->max_num_pages, $range = 2 ); ?>
    
        </div><!-- #page-content -->
    
    <?php get_footer(); ?>

    The pagination function:

    function v_pagination( $pages = '', $range = 2 ) {
    $showitems = ( $range * 2 ) + 1;
    global $paged;
    
    if ( empty( $paged ) ) $paged = 1;
    if ( $pages == '' ) {
        global $wp_query;
        $pages = $wp_query->max_num_pages;
    
        if ( !$pages ) {
            $pages = 1;
        }
    }   
    
    if ( 1 != $pages ) {
        echo "<div class='pagination-container'>\n<div class='pagination'>";
        if ( $paged > 2 && $paged > $range+1 && $showitems < $pages ) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
        if ( $paged > 1 && $showitems < $pages ) echo "<a href='".get_pagenum_link( $paged - 1 )."'>&lsaquo;</a>";
    
        for ( $i=1; $i <= $pages; $i++ ) {
            if ( 1 != $pages &&( !( $i >= $paged+$range+1 || $i <= $paged-$range-1 ) || $pages <= $showitems ) ) {
                echo ( $paged == $i )? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link( $i )."' class='inactive' >".$i."</a>";
            }
        }
    
        if ( $paged < $pages && $showitems < $pages ) echo "<a href='".get_pagenum_link( $paged + 1 )."'>&rsaquo;</a>";
        if ( $paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages ) echo "<a href='".get_pagenum_link( $pages )."'>&raquo;</a>";
        echo "</div>\n</div>\n";
    }
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Pagination not working in page template’ is closed to new replies.