• I am using the loop as you can see in my code. Only 2 posts must be shown and for the rest I should be able to have pagination.

    <?php
    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    query_posts(
    array (
    ‘posts_per_page’ => 2,
    ‘post_type’ => ‘post’,
    ‘category_name’ => ‘news’,
    ‘category’ => 1,
    ‘paged’ => $paged )
    );
    // The Loop
    while ( have_posts() ) : the_post();?>
    <div class=”news-page-content-wrapper”>
    <div class=”news-page-content”>
    <h1>“><?php the_title();?></h1>
    <figure><?php the_post_thumbnail(); ?></figure>
    <p><?php echo get_the_excerpt();?></p>
    “>Read More&raquo
    </div>
    </div>
    <?endwhile;
    // Reset Query
    wp_reset_query();
    ?>
    <?php next_posts_link(); ?>
    <?php previous_posts_link(); ?>

    How can I have pagination using the loop with category ID?

Viewing 1 replies (of 1 total)
  • Try this,
    set ‘Blog pages show at most’ is 2(Settings->Reading)
    $paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1;
    $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘post_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘news’, ‘field’ => ‘id’, ‘terms’ => 1, ) ), ‘paged’ => $paged ); $loop = new WP_Query($args); while($loop->have_posts()) : $loop->the_post(); ?>
    <div class=”news-page-content-wrapper”>
    <div class=”news-page-content”>
    <h1>“><?php the_title();?></h1>
    <figure><?php the_post_thumbnail(); ?></figure>
    <p><?php echo get_the_excerpt();?></p>
    “>Read More&raquo
    </div>
    </div>
    <?endwhile;
    ?>
    <?php next_posts_link(); ?>
    <?php previous_posts_link(); ?>
    <?
    // Reset Query
    wp_reset_query();
    ?>

    Regards,
    Sarmistha

Viewing 1 replies (of 1 total)
  • The topic ‘How to add pagination to custom page’ is closed to new replies.