Pagination trouble

Home Forums Plugin Integration Pagination trouble

This topic is: not resolved

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  middlesister 3 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4107

    shenanigans
    Participant

    Hey guys,

    I’m having trouble getting pagination to work in my Thematic child theme. It kinda works… partly, but not as desired. On my site I’m calling a custom loop:

    <code><?php
    				if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
    				elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
    				else { $paged = 1; }
    				$my_query = new WP_Query('cat=33&#038;paged='.$paged);
    					while ($my_query->have_posts()) : $my_query->the_post();
    					$do_not_duplicate = $post->ID;
    					?></code>
    

     

    I didn’t include the whole loop when I call CSS code and the like to reduce confusion…

    I also added a function in my functions.php. It’s where I tell WP to include a pagination in my childtheme:

    <pre><code><?php
    function absolutip_custom_pagination() {
    	if(is_front_page() || is_page('blog') ) { ?>
    		<div class="pagination">
    			<?php posts_nav_link(); ?>
    			<?php
    				global $my_query;
    
    				$big = 999999999;
    				echo paginate_links( array(
    				'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    				'format' => '?paged=%#%',
    				'total' => $my_query->max_num_pages,
    				'prev_next' => $my_query->True,
    				'prev_text' => __( $big, '&laquo; Previous'),
    				'next_text' => __( $big, 'Next &raquo;')
    			) ) ?>
    			<?php
    				if (have_posts()) : while (have_posts()) : the_post();
    				if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts);
    			?>
    			<?php endwhile; endif; ?>
    		</div>
    	<?php
    	}
    }
    add_action( 'thematic_belowcontent', 'absolutip_custom_pagination' );
    ?></code></pre>
    

    Somehow pagination never shows the << Previous | Next >> link. It does show up however, if I add 'current' => 1, to my absolutip_custom_pagination function. However, then the link to page 1 can’t be clicked anymore…

    Can anyone help me with that? Could it be that my pagination doesn’t know what page it’s on?

    Thanks so much

    #4121

    middlesister
    Keymaster

    I would expect two sets of navigation links to show up since you also call posts_nav_link() above the other set. But I think your parameters to the paginate_links function are a bit off. What is the purpose of the $big variable?

    I would try first with not setting the ‘base’, or the ‘format’ parameters and let it use the defaults and see what shows up.

    If you need to change it, the ‘base’ parameter requires the string %_%, which is where the string of the ‘format’ parameter will be placed. A the moment that is missing. The parameter of the get_pagenum_link refers to the page ID, and you are on the front page. Does that really have an ID of 999999999? Try setting the ‘base’ string to ‘http://www.yoursite.com%_%’ if you want to target the homepage.

    The default of ‘prev_next’ is already true, so no need to send that.

    The ‘prev_text’ and ‘next_text’ are the text to display on the links. The __() part is the internationalization of that text. There is no need to put $big in there.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Pagination trouble’ is closed to new replies.