WordPress.org

Ready to get started?Download WordPress

Forums

Adding pagination to custom post query (2 posts)

  1. rikardo85
    Member
    Posted 11 months ago #

    Hello,

    I have a page that displays posts from a specified category.

    I have 10 posts showing but I would like there to be pagination for the option to view previous posts.

    The code I am using to generate the posts is:

    <section class="front-page archives clear">
       <section class="archive">
    
    <?php $query = new WP_Query( array(
    			'post_type' => 'post',
    			'category_name' => 'press',
    			'posts_per_page' => 8,
    			'order' => desc
    			) ); ?>
    
    <?php while ($query->have_posts()) : $query->the_post(); ?>
      <?php if (empty($post->post_excerpt))
        { ?>
           <div class="news">
    	<div class="newsImgPage">
             <?php the_post_thumbnail();?>
            </div>
    	<div class="newsTextPage">
    	  <h2><?php the_title(); ?></h2>
    	  <span class="nDate"><?php the_date( 'F j Y' ); ?></span>
    	  <p><?php the_content(); ?></p>
    	</div>
           </div>
      <?php }
    	else
    	{ ?>
    	 <div class="news">
    	  <div class="newsImgPage">
                <?php the_post_thumbnail();?>
              </div>
    	  <div class="newsTextPage">
    	   <h2>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
               </h2>
    	   <span class="nDate"><?php the_date( 'F j Y' ); ?></span>
    	   <p><?php the_excerpt(); ?></p>
    	  </div>
    	 </div>
    	<?php
    	}
             endwhile; ?>
    </section>
    </section>

    Any help much appreciated

    Thanks

  2. alchymyth
    The Sweeper & Moderator
    Posted 11 months ago #

Reply

You must log in to post.

About this Topic