WordPress.org

Support

Support » Plugins and Hacks » wp-pagenavi in custom query

wp-pagenavi in custom query

  • I realise this is in the FAQs page but I just cannot get this to show the page navigation. I would ideally like the nav to show above and below the posts. I have the following…

    <?php /* Start the Loop */
    $my_query = new WP_Query( array(
    	'cat' => '1',
    	'posts_per_page' => '5',
    	'paged' => get_query_var('paged'),
    	'orderby' => 'rand'));
    while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_excerpt(); ?>
    <?php endwhile; /* End the Loop */ ?>
    <?php wp_pagenavi(); ?>
    <?php wp_reset_query(); ?>

    Sorry if this is really obvious but I can’t get pagenavi to work here.

    http://wordpress.org/extend/plugins/wp-pagenavi/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Okay, managed to get it to appear at the bottom but is there any way to get it to appear at the top of a custom query as well?

    <?php
    $my_query = new WP_Query(array(
    	'cat' => '1',
    	'posts_per_page' => 5,
    	'paged' => get_query_var('paged')));
    while ( $my_query->have_posts() ) : $my_query->the_post();?>
    <h2><?php the_title(); ?></h2>
    <?php
    	endwhile;
    	wp_pagenavi( array( 'query' => $my_query ) );
    ?>

    Hi, greencode. You got the most of the answer of what I needed. To complete it, I moved the wp_pagenavi function code to the top of the loop like this:

    <?php
    $my_query = new WP_Query(array(
    	'cat' => '1',
    	'posts_per_page' => 5,
    	'paged' => get_query_var('paged')));
    
    wp_pagenavi( array( 'query' => $my_query ) );
    
    while ( $my_query->have_posts() ) : $my_query->the_post();?>
    <h2><?php the_title(); ?></h2>
    <?php
    	endwhile;
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp-pagenavi in custom query’ is closed to new replies.