Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Possible Duplicate:
Pagination not working with custom loop

So I have a post type called portfolio, but I can't get it to paginate. I'd also like it to paginate on single pages so each item has a prev/next link at the bottom, but this won't work either.

I try adding this on the single page and the links just don't appear.

I've been banging my head against a brick wall for days now trying to find a solution for this and nowhere online can I find one.

<div class="next-posts"><?php next_posts_link('Older Posts') ?></div>
            <div class="prev-posts"><?php previous_posts_link('Newer Posts') ?></div>




<?php
                                 $portfolio_query = new WP_Query(array(
                                'post_type' => 'portfolio',
                                'showposts' => -1
                                ) );
                           ?>


                           <?php while ($portfolio_query->have_posts()) : $portfolio_query->the_post(); ?>

                            <?php global $more; $more = 0; ?>

                         <div class="portthumbwrap">

                         <a href="<?php the_permalink() ?>">
                            <div class="portmetacontainer">
                                <div class="link-text">
                                    <h2><?php the_title(); ?></h2>

                                    <ul>
                                     <?php
                                        $posttags = get_the_tags();
                                        if ($posttags) {
                                          foreach($posttags as $tag) {
                                            echo '<li>' .$tag->name. '</li>'; 
                                          }
                                        }
                                        ?>

                                    </ul>   

                                </div> <!-- end div link-text -->

                            </div> <!-- end div postmetacontainer -->
                         </a>

                           <div class="figure">

                                <?php the_post_thumbnail(); ?>

                           </div>


                         </div> <!-- end div portthumbwrap -->











                           <div class="clearfix"></div>
                           <?php endwhile; wp_reset_query(); ?>
share|improve this question

marked as duplicate by Chip Bennett, s_ha_dum, toscho Jan 29 '13 at 22:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
why do you create a new query for your portfolio items? what template are you using this in? what happens if you just run the default loop? for single views you want next_post_link, note that it's singular post, not plural posts. –  Milo Jan 29 '13 at 16:21
    
It says 'posts' here. codex.wordpress.org/Function_Reference/previous_posts_link Why not create a new query for the portfolio posts? I'm not being sarcastic or anything, I really don't know, the WP codex seems geared towards people that are experts in php. And the template is one I made. –  andy Jan 29 '13 at 19:09
    
Please search for related questions before posting. –  Chip Bennett Jan 29 '13 at 19:36
add comment

2 Answers 2

The problem with your custom query is that you pass no pagination parameters, and it has no relationship to the default query variables that pagination functions operate with.

When you register your portfolio post type, set has_archive to true and rewrite slug to the URL you want your portfolio items to appear at:

'rewrite' => array( 'slug' => 'portfolio' )

then use the default loop in your template:

while( have_posts() ):
    the_post();
    the_title();
    // etc...
endwhile;

and the pagination functions will just work without you having to do anything else.

If you want to customize the template from other post archives, name your template archive-portfolio.php where portfolio is the name you've registered your post type as. See the Template Hierarchy for more info.

next_posts_link (plural) is for an archive page, next_post_link (singular) is the next single post after the current single post being viewed.

share|improve this answer
    
I just changed next_posts_link to post (singular) and added 'archive' to the 'supports' array. Now it paginates just fine on the single page. Is that 'right' in technical sense? –  andy Jan 29 '13 at 23:07
add comment

I believe if posts_per_page is set to -1 you're showing all posts without pagination. Try setting it to 5 for example.

share|improve this answer
    
Also see this reference about setting up pagination wp-snippets.com/pagination-without-plugin –  Owain Cuvelier Jan 29 '13 at 16:11
add comment

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