• Hello,
    For some reason I can’g get pagination using previous_posts_link and next_posts_link working.

    Here is the code I have…

    <?php // The Query
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    $the_query = new WP_Query(
    	array(
    		'post_type'=>'article',
    		'posts_per_page'=>2,
    		'orderby'=>'date',
    		'paged'=>$paged
    	)
    );
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    
    	if($the_query->current_post == 0 && $paged == 1) :
    	?>
    	<article class="latest">
    		<div class="summary">
    			<h4>LATEST ARTICLE:</h4>
    
    			<h2><?=the_title(); ?></h2>
    			<div class="entry-meta">
    				<?php proagent_posted_on(); ?>
    			</div><!-- .entry-meta -->
    			<div class="entry-content">
    				<?=get_the_content_limit(300, 'More'); ?>
    
    			</div><!-- .entry-content -->
    
    			<div class="entry-topics"><?=get_the_term_list($post->ID , 'topics', 'Topics: ',', '); ?></div>
    		</div>
    		<?=the_post_thumbnail('feature-post-thumbnail'); ?>
    	</article>
    
    	<?php else: ?>
    	<article class="previous">
    		<?=the_post_thumbnail(); ?>
    		<div class="summary">
    			<h2><?=the_title(); ?></h2>
    			<div class="entry-meta">
    				<?php proagent_posted_on(); ?>
    			</div><!-- .entry-meta -->
    			<div class="entry-content">
    				<?=get_the_content_limit(300, 'More'); ?>
    
    			</div><!-- .entry-content -->
    
    			<div class="entry-topics"><?=get_the_term_list($post->ID , 'topics', 'Topics: ',', '); ?></div>
    		</div>
    	</article>
    	<?php endif; ?>
    
    <?php endwhile; ?>
    <nav id="nav-below" class="navigation">
    	<div class="alignleft"><?php previous_posts_link('« Newer Articles') ?></div>
        <div class="alignright"><?php next_posts_link('Older Articles »') ?></div>
    </nav><!-- #nav-below -->

    Also.. just noticed it works when I go to /articles/page/2 there is a link to /articles/ like there should be but from the /articles/ page there is no link to page 2.. WHY?

    PLEASE help if you can… this is driving me crazy.

    Thanks! mark.

Viewing 1 replies (of 1 total)
  • Thread Starter markstewie

    (@markstewie)

    After 7 hours and no help I’ve finally worked it out by a fluke.
    So if anyone else is having trouble with this the answer is NOT to use anything other than a variable called $wp_query to hold the post query. I was using $the_query and that was what was breaking the pagination… I’ve got no hair left after ripping it out for hours but at least I’ve worked it out.

Viewing 1 replies (of 1 total)

The topic ‘Pagination with custom post type not working’ is closed to new replies.