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

Heath Hughes
Heath Hughes
19,766 Points

Ajax pagination for custom post types

I'm trying to figure out how to implement ajax pagination for a group of links displayed on a static page.

This is what I have right now without pagination:

<?php
    $args = array(
        'post_type' => 'work'
    );

    $the_query = new WP_Query( $args );
?>

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

    <div class="grid-4 project">
        <a href="<?php the_permalink() ;?>?iframe=true&width=100%&height=100%" rel="prettyPhoto[project]">
            <img src="<?php the_field('featured_image'); ?>"> 
            <h2><?php the_title(); ?></h2>
            <p><?php the_excerpt(); ?></p>
        </a>
    </div>

<?php endwhile; else: ?>
    <p><?php _e('Sorry, no projects were found.'); ?></p>
<?php endif; ?>

In the code above, I am displaying links to each post that will be opened in a lightbox-esque modal. I'd like to display six at a time and be able to use ajax pagination to "scroll" through them.

I'm new to ajax and pagination in WordPress and I can't seem to find what I need in the codex or plugins. Can anyone point me in the right direction?