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.
<div class="single_post">
    <?php
    // The Query
    query_posts( $args );
    // The Loop
    if(have_posts()) :
    while ( have_posts() ) : the_post();
    ?>
    <div class="left_date">
        <h1><?php the_time('d') ?></h1>
        <p><?php the_time('M') ?></p>
        <span class="year"><p><?php the_time('Y') ?></p></span>
    </div>
    <a href="<?php the_permalink(); ?>" ><h2><?php the_title(); ?></h2></a>
    <div class="author_tag">
        <span class="author">By: <?php the_author_posts_link(); ?></span>
        <span class="tag"><?php the_tags(); ?></span>
    </div>
    <div class="post">
        <p><?php the_content(); ?></p>
        <div class="read_comment">
            <a href="#" title="Full post"><span class="read">Read more</span></a>
            <a href="#" title="Comment here"><span class="comment">Comment</span></a>
        </div>
    </div>
    <div class="clear"></div>
    <div class="gap"></div>
    <?php
        endwhile;
        endif;
        // Reset Query
        wp_reset_query();
    ?>
    <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts') ); ?></div>
    <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>') ); ?></div>
</div>

The whole code works fine. But the last two line ain't working, I mean the next posts and previous posts button ain't appeared.

<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts') ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>') ); ?></div>

Why is this happening? Is it for query_posts( $args ) function what I used? What should I do now? I just want to show that two paginate link. I believe the solution should be very simple.

share|improve this question
    
Why query_posts not WP_Query? Citation from query_posts Caveats: "Before deciding to use query_posts(), be sure to understand the drawbacks.". –  Max Yudin Mar 16 '13 at 9:28
add comment

2 Answers

up vote 0 down vote accepted

Just put them between endwhile; and endif;

share|improve this answer
    
Thanks a lot. It's working now, they are appeared. But one new problem here, when I click on the "older posts" or "newer posts", it shows the same posts. It's not going to other posts. Could you solve that too? I am going to accept your question. –  Shahriar Mar 16 '13 at 8:08
    
Are the navigation shown links different than current post url? –  revo Mar 16 '13 at 8:30
    
I think Yes. It's different. It's the main link where current posts are stayed localhost/wp/blog When I click on the "older posts" button, the url becomes localhost/wp/blog/page/2 But the posts are same as localhost/wp/blog link. –  Shahriar Mar 16 '13 at 8:35
    
what are the $args for the query? –  Michael Mar 16 '13 at 9:11
    
Actually I don't know much about wordpress. When I use query_posts( $args ); ..... wp_reset_query(); the posts appear fine. But If I don't use them, my posts don't show up. So I just use them. I believe there is any kind of conflicting issue between 'query_post' and navigation'next_posts_link' + 'previous_posts'. Could you help me without any major changing in the code? @Michael –  Shahriar Mar 16 '13 at 9:19
show 2 more comments

The issue here is that you are trying to add the navigation options after resetting the query, this is needed by the navigation methods to setting accurately those values needed.

Just Move your wp_reset_query() below your navigation lines.

share|improve this answer
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.