6
<?php
/*
Template Name: Projects
*/
?>

<?php get_header();?>

    <section id="content">
        <section id="main">

            <?php
                $loop = new WP_Query(array('post_type' => 'projects', 'posts_per_page' => 4));
                $i=1;
                while ( $loop->have_posts() ) : $loop->the_post();
            ?>

            <article class="post<?php if($i%2 == 0) { echo ' right'; }; $i++; ?>" id="post-<?php the_ID(); ?>">
                <h2><?php the_title(); ?></h2>
                <section class="entry">
                    <?php the_excerpt(); ?>
                </section>
            </article>

            <?php
                endwhile;
                wp_pagenavi();
            ?>

            <section id="map">
                <img src="<?php bloginfo('template_url') ?>/images/interactive-map.jpg" alt="Interactive Map" />
            </section>
        </section>

<?php get_sidebar(); ?>

    </section>

<?php get_footer(); ?>

I have pagenavi set up right after the endwhile. It's not working, though. Anybody know how I can get this to work?

4
  • see - wordpress.stackexchange.com/questions/4696/… (basically you need to hijack the $wp_query global and use it instead of $loop Feb 17, 2011 at 5:01
  • I followed the directions in there and the navigation shows now but when I go to page 2, I get an error. Here is the pastebin of what I have. If you can take a look and let me know if you notice anything wrong, I'd be forever grateful. Thank you. pastebin.com/RMZaE6Pi
    – J82
    Feb 17, 2011 at 5:52
  • what is the error you are getting?
    – Bainternet
    Feb 17, 2011 at 9:45
  • @One Trick Pony: Can you move your comment to an answer, so John can accept it? Maybe include my comment in the referenced answer, because with the new version of WP-Pagenavi you can pass a query argument. John asked a followup question to get the paging working.
    – Jan Fabry
    Feb 17, 2011 at 14:29

2 Answers 2

19
wp_pagenavi( array( 'query' => $loop ) );

should work with the code above. Don't hijack the main query if you can avoid it.

10
  • My source for this: plugins.trac.wordpress.org/browser/wp-pagenavi/trunk/… Feb 17, 2011 at 14:29
  • Indeed, the development version of WP Pagenavi (2.74-alpha) supports this.
    – scribu
    Feb 17, 2011 at 14:34
  • Oh, I didn't realize this was the dev version. Oops! Feb 17, 2011 at 14:37
  • is this possible with paginate_links() ? Feb 17, 2011 at 14:46
  • paginate_links is somewhat more basic. Instead of giving it a query object, you tell it what the max number of pages are, what the current page is, and a few other parameters (like the format of the url, etc.) Feb 17, 2011 at 14:56
-1
<?php       // Pagination
        if(function_exists('wp_pagenavi')) :
            wp_pagenavi( array( 'query' => $blog_posts_query ) );
        else : ?>
            <div class="navigation">
                <div class="alignleft"><?php previous_posts_link() ?></div>
                <div class="alignright"><?php next_posts_link() ?></div>
            </div>
<?php       endif;

                // Restore original Post Data
                wp_reset_postdata(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.