0

I am using the loop in my custom page template 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><a class="read-more"href="<?php the_permalink(); ?>"><?php the_title();?></a></h1>
                <figure><?php the_post_thumbnail(); ?></figure>
                <p><?php echo get_the_excerpt();?></p>
                <a href="<?php the_permalink(); ?>">Read More&raquo</a>
            </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?

2 Answers 2

0

You can follow below URl to find your solution

How to fix pagination for custom loops?

2
  • Links are not helpful as answers. Jan 27, 2020 at 12:28
  • Please edit your answer with the appropriate details. Thanks.
    – Christine Cooper
    Jan 27, 2020 at 14:15
0

You can use the tax_query filter: like this

    $args = array
    (
        'post_type' => 'item',
        'nopaging' => true,
        'tax_query' => array
        (
           'taxonomy' => $taxonomy,
           'field' => 'term_taxonomy_id',
           'terms' => $term_id
        ),
        'meta_query'  => array(
           'key'     => 'from_import',  
           'value'   => '1'
        )
    );
    $posts = query_posts( $args );
1
  • Please edit your answer, and add an explanation: why could that solve the problem?
    – fuxia
    Oct 26, 2020 at 18:08

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.