Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know this sounds illogical and maybe it is, but the client's asked for it so I'm looking into a solution if possible.

On a section of the site there's a link that leads to category-news.php, which displays all posts belonging to News. The user loads each of these posts dynamically through the use of InfiniteScroll, with the posts being paginated beforehand.

The client has requested to also want this feature when viewing a single post item of the same category (i.e. "View more"). I can't seem to create a pagination for single.php, and would like to know if this is even possible to begin with? What happens now is that I get only 1 additional post beyond the current.

Here's the code for single.php so far -

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $currentID = get_the_ID(); ?>
<article>
  <section>
    <?php the_post_thumbnail( array(466,9999) ) ?>
  </section>
  <section>
    <h1><?php the_title() ?></h1>
    <h6><?php the_date() ?></h6>
    <div class="share"><span class='st_sharethis_custom'>Share</span></div>
    <?php the_content(); ?>
  </section>
</article>
<?php endwhile; endif; ?>
<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$news = new WP_Query( array('cat' => 3, 'paged' => $paged, 'posts_per_page' => 1, 'post__not_in' => array($currentID), 'orderby' => 'date', 'order' => 'DESC') );
while ($news->have_posts()) : $news->the_post();
?>
<article>
  <section>
    <?php the_post_thumbnail( array(466,9999) ) ?>
  </section>
  <section>
    <h1><?php the_title() ?></h1>
    <h6><?php the_date() ?></h6>
    <div class="share"><span class='st_sharethis_custom'>Share</span></div>
    <?php the_content(); ?>
  </section>
</article>
<?php endwhile; endif; ?>
<div class="infiniteScroll"><?php next_posts_link('') ?></div>

(Running the current post first, then adding a WP Query to retrieve the rest.)

share|improve this question

1 Answer 1

I think the easiest implementation would be to put your infinite scroll in category.php, and then, either using Dashboard -> Settings -> Reading -> Posts per page, or via direct query modification, display one post per page.

Otherwise, depending on how you're implementing the infinite scroll, you could make use of next_post_link() and previous_post_link(), both of which have an $in_same_cat parameter.

share|improve this answer
    
All these things you mention is exactly what I'm currently doing :) My question is whether it's possible to implement pagination on single.php. –  Staffan Estberg Nov 1 '11 at 21:28
    
I'm not sure I understand? previous_post_link() and next_post_link() are used to implement previous/next post links on single blog posts. Do you mean [1][2][3] type pagination links? –  Chip Bennett Nov 1 '11 at 21:43
    
I'm sorry, maybe I was unclear about the pagination. Right now I'm using the next_post_link() under category-news.php, which is then replaced by the InfiniteScroll function (whereas the URL would otherwise be "/news/page/2"). The same would go for this single.php if possible. –  Staffan Estberg Nov 1 '11 at 21:58
    
Just to make sure: in category-news.php, do you have next_post_link() or next_posts_link()? (Note: post vs posts) –  Chip Bennett Nov 1 '11 at 22:00
    
In category-news.php I'm using next_posts_link() and it works fine. I tried the post without s alternative on single.php but it gave no result - still only showing 1 post after the current. I guess what I want to achieve here is - even if it sounds weird - "news/a-sample-post/page/2". So that when the user lands on a single post (a-sample-post) they are able to continue skimming through the posts on that very page for the category News. –  Staffan Estberg Nov 1 '11 at 22:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.