Skip to content

Instantly share code, notes, and snippets.

@ismailfazal
Created May 12, 2014 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismailfazal/519f25576fd98d8f828a to your computer and use it in GitHub Desktop.
Save ismailfazal/519f25576fd98d8f828a to your computer and use it in GitHub Desktop.
Add wordpress recent posts from same category to single post page with infinite scroll
<?php
$categories = get_the_category();
$category_id = $categories[0]->cat_ID;
query_posts( 'cat='.$category_id );
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- You can use your loop content here, i have used roots wordpress theme -->
<?php get_template_part('templates/content', get_post_format()); ?>
<?php endwhile; else: ?>
<!-- DO SOMETHING IF NOTHING WAS FOUND -->
<?php endif; ?>
<!-- Here i have used roots navigation, if you use wordpress default navigation copy it from index page -->
<?php if ($wp_query->max_num_pages > 1) : ?>
<nav class="post-nav">
<ul class="pager">
<li class="previous"><?php next_posts_link(__('&larr; Older posts', 'roots')); ?></li>
<li class="next"><?php previous_posts_link(__('Newer posts &rarr;', 'roots')); ?></li>
</ul>
</nav>
<?php endif; ?>
<?php wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment