1

My question is not new but it just does not work with all found solutions in my case.

I am trying to display recent posts on single post using custom query_posts loop. The permalinks structure must be this one: /%category%/%postname%/

Wordpress version: 3.2.1

The page has 2 loops:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <!--first content part-->
<?php endwhile; endif;?>

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('posts_per_page=3&paged='.$paged);

if (have_posts()) : while (have_posts()) : the_post(); ?>
    <!--recent posts-->
<?php endwhile; endif; wp_reset_query();?>

So calling next page like http://www.domain.com/category/post-one/page/2/ simply strips off /page/2/ and does nothing else.

I am desperate already for looking a working solution and not sure if its possible to fix.

Thank you.

1
  • Test with one of the provided permalink structures(just not default or custom), eg. Day and Name, if that resolves the issue you know what the problem is.
    – t31os
    Aug 17, 2011 at 8:56

1 Answer 1

1

From the WP Codex for WP_Query:

Show Posts from Current Page

Display posts from current page:

$query = new WP_Query( 'paged=' . get_query_var( 'page' ) );

Pagination Note: You should set get_query_var( 'page' ); if you want your query to work with pagination. Since Wordpress 3.0.2, you do get_query_var( 'page' ) instead of get_query_var( 'paged' ). The pagination parameter 'paged' for WP_Query() remains the same.

Changing the query var from 'paged' to 'page' will result in the following code:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <!--first content part-->
<?php endwhile; endif;?>

<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
query_posts('posts_per_page=3&paged='.$paged);

if (have_posts()) : while (have_posts()) : the_post(); ?>
    <!--recent posts-->
<?php endwhile; endif; wp_reset_query();?>
4
  • Just tried your solution but no luck. It does not work and still strips off /page/2/ remaining on the same page. Maybe your solution works for default permalink structure or just index page. But my case it does not resolve :(((( any idea what could i try else. It seems so simple the idea... just to display recent posts with pagination on single post template.
    – Alex
    Aug 17, 2011 at 0:33
  • Perhaps the page query var is protected. Try passing your own variable such as mypage. To use mypage you will need to use add_filter to add a query var and a rewrite rule. WP_Rewrite Codex will give you more information on rewrite and has an example to do what I just mentioned. Aug 17, 2011 at 1:35
  • I think that note is incorrect, @scribu introduced that note on the codex entry, but i think it's actually incorrect, page and paged have different meaning, paged refers to pagination for archives, where as page refers to the pages of a single entry(a multiple page post for example - eg. when you use <!--nextpage-->). Perhaps scribu misinterpreted it's usage, or perhaps i'm even misunderstanding the usage myself.
    – t31os
    Aug 17, 2011 at 14:32
  • Very sad that there is no really clear explanation about that. Anyway, page or paged still did not work. I would try what @scribu said but i am not very programming savvy and doubt i would get the correct piece of code for my example. Maybe someone could get a hand on that solution.
    – Alex
    Aug 17, 2011 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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