Support » Fixing WordPress » WP-Paginate does not work for custom query

  • Code Themes

    (@codepixelzmedia)


    Hi, I installed WP-paginate plugin and now want pagination for my custom query so i put the following code, but it does not show any pagination links.

    <?php
    		//wp_reset_query();
    		$current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$query = new WP_Query( 'category_name=news&posts_per_page=10&paged='.$current_page );
    		if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
     <?php comments_number( '0 comments', '1 response', '% responses' ); ?> | <?php the_time('M j Y') ?><br />
     Posted in: <?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);
    }
    ?>
      <?php the_excerpt();?>
      <hr />
     	<?php endwhile;
    	?>
    
        <?php
    	 else: ?>
    
    	<?php endif; ?>
    	<div class="navigation">
    			<?php if(function_exists('wp_paginate')) {
        wp_paginate(false,$query);
    } ?>

    I did search previously on the forum, I found a similar issue at http://wordpress.org/support/topic/wp-paginate-and-custom-queries but didn’t help. I would be thankful if you could help.

  • The topic ‘WP-Paginate does not work for custom query’ is closed to new replies.