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.

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.

share|improve this question
    
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 '11 at 8:56
add comment

migrated from stackoverflow.com Aug 16 '11 at 23:46

This question came from our site for professional and enthusiast programmers.

1 Answer

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();?>
share|improve this answer
    
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 '11 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. –  Steve Buzonas Aug 17 '11 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 '11 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 '11 at 17:35
add comment

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.