• Hi, I am having trouble getting my pagination code to work. It properly lists the pages (1,2,3,4 Next) but the “Next” link is always page 2. It appears the $paged variable is always 1

    <?php
    						$num_of_pages = ($post_count / $posts_per_page);
    						//$link_number = 0;
    						if($num_of_pages > 1):?>
    						<?php
    						global $paged;
    						if(empty($paged)) $paged = 1;
    						?>
    						<div class="pagination2">
    							<ul class="clear1">
    								<?php if( ($paged <= $num_of_pages) && ($paged > 1) ): ?>
    								<li><a href="/library/blog/?paged=<?php echo $paged-1; ?>">Previous</a></li>
    								<?php endif; ?>
    								<li<?php if($paged==1) {echo ' class="current"';}?>><a href="/library/blog/?paged=1">1</a></li>
    								<?php for ($i = 1; $i < $num_of_pages; $i++): ?>
    								<li<?php if($paged==($i+1)) {echo ' class="current"';}?>><a href="/library/blog/?paged=<?php echo $i+1; ?>"><?php echo $i+1; ?></a></li>
    								<?php endfor; ?>
    								<?php if( $paged < $num_of_pages ): ?>
    								<li><a href="/library/blog/?paged=<?php echo $paged+1; ?>">Next</a></li>
    								<?php endif; ?>
    							</ul>
    						</div>
    						<?php endif; ?>
Viewing 1 replies (of 1 total)
  • Thread Starter Josh

    (@ikjosh)

    Here is my query

    function get_url_var($name)
    {
    	$strURL = $_SERVER['REQUEST_URI'];
    	$arrVals = split("/",$strURL);
    	$found = 0;
    	foreach ($arrVals as $index => $value)
    	{
    		if($value == $name) $found = $index;
    	}
    	$place = $found + 1;
    	return $arrVals[$place];
    }
    
    $paged = get_url_var('page');
    
    $url = CurrentPageURL();
    //echo $paged;
    
    //if ( get_query_var('paged') ) $paged = get_query_var('paged');
    //if ( get_query_var('page') ) $paged = get_query_var('page');
    $posts_per_page = 3;
    $args = array(
    	'posts_per_page' => $posts_per_page,
    	'post_type' => 'post_library',
    	'tax_library_cats' => 'blog',
    	'post_status' => 'publish',
    	'paged' => $paged,
    	'caller_get_posts'=> 1
    );
    $the_query = new WP_Query( $args );
    
    $post_count = $the_query->found_posts;
    //print '<pre>'; print_r($the_query); print '</pre>';
    while ( $the_query->have_posts() ) : $the_query->the_post();
Viewing 1 replies (of 1 total)
  • The topic ‘Need help with my Pagination code’ is closed to new replies.