Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Stanley Thijssen
Stanley Thijssen
22,831 Points

How to make pagination for your custom post type on wordpress

I was trying to get my pagination to work on my custom post type but cant get it to work.

I used the following code:

<?php get_header(); ?>
            <section id="content">
                <aside class="left-col">
                    <?php dynamic_sidebar( 'linker-sidebar' ); ?>
                </aside>
                <article class="right-col">
                    <section id="slider">
                    <?php nivo_slider( "home-slider" ); ?>
                    </section>
                    <ul class="productthumbnails">
                        <?php
                        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                        $mijnProducten = new WP_Query( array(
                        'post_type' => 'producten',
                        'posts_per_page' => 3,
                        'orderby'=> 'menu_order',
                        'paged'=>$paged
                        ) );
                        while( $mijnProducten->have_posts() ) : $mijnProducten->the_post();
                        ?>
                            <li><?php the_post_thumbnail( 'postpage'); ?> <h2><?php the_title(); ?></h2> </li>
                        <?php
                        endwhile; ?>
                        <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
                        <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
                    </ul>
                </article>
            </section>
        </div>
        <?php get_footer(); ?>

can anybody help?

2 Answers

Stanley Thijssen
Stanley Thijssen
22,831 Points

Hi Zac Thanks. This made the prev_posts link and next_posts link work. Only when i click on older posts now or newer posts, It doesn't show any posts but i do have more posts.