WordPress.org

Ready to get started?Download WordPress

Forums

WP-PageNavi
wp-pagenavi in custom query (3 posts)

  1. greencode
    Member
    Posted 11 months ago #

    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/

  2. greencode
    Member
    Posted 11 months ago #

    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 ) );
    ?>
  3. joldigital
    Member
    Posted 6 months ago #

    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;
    ?>

Reply

You must log in to post.

About this Plugin

About this Topic