• hi, so far I have about 11 posts and I am showing 6 on my page but I am unable to get the NEXT | PREVIOUS pagination working?!

    here is my code:

    <?php
    
    			$paged = (get_query_var('paged')) ? get_query_var('paged') : 0;
    
    			$postsPerPage = 6;
    			$postOffset = $paged * $postsPerPage;
    
    			$args = array(
    				'numberposts' => -1,
    				'posts_per_page'  => $postsPerPage,
    				'offset'          => $postOffset,
    				'post_type'       => 'article'
    			);
    
    			$posts = get_posts($args);
    
    			if($posts)
    			{
    
    				foreach($posts as $post)
    				{
    					echo '<div class="block col-sm-4 col-md-4">';
    					echo '<h2><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></h2>';
    					echo get_field("article_title") .'<br />';
    					echo get_field("date_posted") .'<br />';
    					echo '<a href="' . get_permalink($post->ID) . '"><img src="'.get_field("article_thumb").'" height="300" /></a>';
    					echo '</div>';
    
    				}
    
    			}
    			?>

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

    (@jbiddulph)

    ok, I was missing the query_posts() function, I added it in and now I get NEXT | PREVIOUS although page one has 6 items and Page 2 has 0

    <?php
    
    			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    			$postsPerPage = 6;
    			$postOffset = $paged * $postsPerPage;
    
    			$args = array(
    				'numberposts' => -1,
    				'posts_per_page'  => $postsPerPage,
    				'offset'          => $postOffset,
    				'post_type'       => 'article'
    			);
    			query_posts('post_type=article&paged='. get_query_var('paged'));
    			$posts = get_posts($args);
    
    			if($posts)
    			{
    
    				foreach($posts as $post)
    				{
    					echo '<div class="block col-sm-4 col-md-4">';
    					echo '<h2><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></h2>';
    					echo get_field("article_title") .'<br />';
    					echo get_field("date_posted") .'<br />';
    					echo '<a href="' . get_permalink($post->ID) . '"><img src="'.get_field("article_thumb").'" height="300" /></a>';
    					echo '</div>';
    
    				}
    
    			}
    			?>
Viewing 1 replies (of 1 total)
  • The topic ‘adding pagination to my custom page’ is closed to new replies.