Support » Fixing WordPress » Pagination…ripping my hair out.

  • Hello. Last night I came across a mix between pagination and infinite scrolling, and decided to implement it.
    It went fine, no hiccups.

    Today, a client told me “hey, I like that” when they saw it on my portfolio, so I figured I would set it up for them.

    I have spent the better part of the past 4 hours trying to get the dang thing to work…why isn’t it working this time? All it does it load the same posts over and over again.

    Here is my query:

    <?php
    	// the query
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$args = array(
    		     'post_type' => 'post',
    		     'paged' => $paged,
    		     'posts_per_page' => 3
    		);
    		$the_query = new WP_Query( $args ); ?>
    		<?php if ( $the_query->have_posts() ) : ?>

    Here is the pagination section:

    <div id="posts_pagination" class="container_12">
    <?php
        global $the_query;
        echo paginate_links( array(
            'base' => '%_%',
            'format' => '?page=%#%',
            'current' => max( 1, get_query_var('paged') ),
            'total' => $the_query->max_num_pages,
            'prev_text' => 'Prev',
            'next_text' => 'Load More'
            ));
    ?>
    </div>

    For the infinite scroll plugin, here are my selectors:
    Content Selector: .recent-posts
    Navigation Selector: #posts_pagination
    Next Selector: .next.page-numbers
    Item Selector: .post

    Now if you really wanna dig, here is the entire post loop from the index.php that I have it set up on. (contains the above and what it sits in.) It pulls different meta from posts, etc.

    <ul class="recent-posts container_12">
    		<?php
    		// the query
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$args = array(
    			'post_type' => 'post',
    			'paged' => $paged,
    			'posts_per_page' => 3
    		);
    		$the_query = new WP_Query( $args ); ?>
    
    		<?php if ( $the_query->have_posts() ) : ?>
    			<?php if( empty($currentcount)){
    				$currentcount = 1;
    			}?>
    		  <!-- pagination here -->
    		  <!-- the loop -->
    			 <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		  	 <?php
    		 	/*--Getting some custom post meta--*/
    				$post_id = get_the_ID();
    				$single = 'true';
    				/*--Custom
    				Thumb URL--*/
    				$custom_thumb_url_meta_key = '_custom_thumb_url_meta_value_key';
    				$custom_thumb_url_meta_value = get_post_meta( $post_id, $custom_thumb_url_meta_key, $single );
    				/*--Custom
    				Caption URL--*/
    				$post_caption_meta_key = '_post_caption_meta_value_key';
    				$post_caption_meta_value = get_post_meta( $post_id, $post_caption_meta_key, $single );
    				/*--Full
    				Width Checkbox--*/
    				$full_width_meta_key = '_post_full_width_meta_value_key';
    				$full_width_meta_value = get_post_meta( $post_id, $full_width_meta_key, $single );
    			/*--Done Getting Custom Post Meta--*/
    			?>
    		  <?php
    		 /**
    
    		**/
    		/*Begin Slide Content*/
    		?>
    			<?php
    				if($full_width_meta_value == 1){
    					$width_class = 'grid_12';
    				}else{
    					$width_class = 'grid_6';
    				}
    			?>
    			<li class="<?php echo $width_class;?> post">
    				<a href="<?php echo the_permalink();?>" title="<?php the_title();?>">
    					<span class="recent-bg">
    
    						<?php
    						if (!empty($custom_thumb_url_meta_value)){
    							echo '<img src="' . $custom_thumb_url_meta_value . '" alt="';
    							the_title();
    							echo ' Custom Thumb" />';
    						}elseif ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    						  	the_post_thumbnail();
    						}else{
    							//Do Nothing
    						}
    						?>
    					</span>
    					<span class="recent-sub-pic">
    						<h2><?php the_title();?></h2>
    						<p><?php echo $post_caption_meta_value;?></p>
    					</span>
    					<span class="recent-date">
    						<span class="date-month">
    						<?php the_time('M');?>
    						</span>
    						<span class="date-day">
    							<?php the_time('dS');?>
    						</span>
    					</span>
    				</a>
    				<div class="recent-overlay">
    					<ul class="viewgall-comment">
    						<li class="viewgallery"><a href="<?php echo the_permalink();?>" title="<?php the_title();?>"></a></li>
    						<li class="view-comment"><a href="<?php echo the_permalink();?>#comment-section"></a></li>
    					</ul>
    					<span class="recent-category">
    					<?php
    					$categories = get_the_category();
    					$separator = '   |   ';
    					$output = '';
    						if($categories){
    							foreach($categories as $category) {
    								$output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
    							}
    						echo trim($output, $separator);
    						}
    					?>
    					</span>
    				</div>
    			</li>
    			<?php
    				if($full_width_meta_value != 1){
    					if($currentcount % 2 == 0){
    						echo '<span class="recent-posts-divider grid_12">';
    						echo '</span>';
    						$currentcount++;
    					}
    					else{
    						$currentcount++;
    					}
    				}else{
    					echo '<span class="recent-posts-divider grid_12"></span>';
    				}
    
    			?>
    		<?php
    			/*End Content*/
    			 /**
    
    			**/
    		  ?>
    	  <?php endwhile; ?>
    	  <!-- end of the loop -->
    	  <!-- pagination here -->
    	  <div class="pagination-container">
    
    		  <div id="posts_pagination" class="container_12">
    			<?php
    				global $the_query;
    
    				$big = 999999999; // need an unlikely integer
    
    				echo paginate_links( array(
    					   	'base' => '%_%',
    						'format' => '?page=%#%',
    						'current' => max( 1, get_query_var('paged') ),
    						'total' => $the_query->max_num_pages,
    						'prev_text' => 'Prev',
    	   					 'next_text' => 'Load More'
    					    ));
    				?>
    		</div>
    	</div>
    	  <?php wp_reset_postdata(); ?>
    	<?php else:  ?>
    	  <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    	<?php endif; ?>
    </ul>
Viewing 1 replies (of 1 total)
  • Thread Starter Endlyss

    (@akel-res)

    Ended up giving up on it (Client wasn’t too mad)
    But if anyone can still give me a bit of insight for future reference, that would be awesome?

Viewing 1 replies (of 1 total)
  • The topic ‘Pagination…ripping my hair out.’ is closed to new replies.