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

Adding navigation to related posts on single.php

Hey guys..

What I want to do is use infinite scroll on related posts on single.php to load new post each time user scrolls on bottom of the page, now I'm having problem adapting any infinite scroll to this script below since all of them require me to select "next" button in pagination div, and I don't have it here in this script.

What would be my solution to that?

Thanks so much!

        <?php $orig_post = $post;
        global $post;
        $categories = get_the_category($post->ID);
        if ($categories) {
        $category_ids = array();
        foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
        $args=array(
        'category__in' => $category_ids,
        'post__not_in' => array($post->ID),
        'posts_per_page'=> 1, // Number of related posts that will be displayed.
        'caller_get_posts'=>1,
        'orderby'=>'rand' // Randomize the posts
        );
        $my_query = new wp_query( $args );
        if( $my_query->have_posts() ) {
        echo '<div id="perfect-related_by-category" class="clear"><h3>Related Posts</h3><ul>';
        while( $my_query->have_posts() ) {
        $my_query->the_post(); ?>
        <li>
         <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>">
         </a>
         <div class="perfect-related_by-category">
         <a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
         </div>
        </li>
        <? }
        echo '</ul></div>';
        } }
        $post = $orig_post;
        wp_reset_query(); ?>