Created
May 12, 2014 11:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(__('← Older posts', 'roots')); ?></li> | |
<li class="next"><?php previous_posts_link(__('Newer posts →', '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