• Resolved Reed Gustow

    (@echofoxtrot)


    I have the following code in my site. The navigation links do not appear; I only see empty div tags.

    What am I doing incorrectly? Thanks in advance for any help you can provide.

    [please mark any posted code – http://codex.wordpress.org/Forum_Welcome#Posting_Code ]

    $temp = $wp_query;
    $wp_query = null;
    $paged = (get_query_var ('paged') ) ? get_query_var ('paged') : 1;
    $priorPosts = new WP_Query('offset=2&cat=-37&paged=' .$paged);
    while($priorPosts->have_posts() ):
    $priorPosts->the_post();
    ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php endwhile; ?>
    
    <div class="paging">
    <div class="right"><?php previous_posts_link(); ?></div>
    <div class="left"><?php next_posts_link (); ?></div>
    </div>
    <?php
    $wp_query = null;
    $wp_query = $temp;
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Try changing these lines:

    $temp = $wp_query;
    $wp_query = null;
    $paged = (get_query_var ('paged') ) ? get_query_var ('paged') : 1;
    $priorPosts = new WP_Query('offset=2&cat=-37&paged=' .$paged);
    while($priorPosts->have_posts() ):
    $priorPosts->the_post();

    to this:

    $temp = clone $wp_query;
    $wp_query = null;
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    query_posts('offset=2&cat=-37&paged=' .$paged);
    while( have_posts() ):
       the_post();

    and this:

    $wp_query = $temp;

    to this:

    $wp_query = clone $temp;
    Thread Starter Reed Gustow

    (@echofoxtrot)

    Thanks, vtxyzzy! I will give that a shot. Much appreciated!

    you have actually done fine with using WP_Query()http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts?rq=1

    for the pagination try:

    <div class="right"><?php previous_posts_link('&laquo; Previous Page', $priorPosts->max_num_pages ); ?></div>
    <div class="left"><?php next_posts_link ('Next Page &raquo;', $priorPosts->max_num_pages ); ?></div>

    however, with the ‘offset’ parameter in the query, pagination will not work. you will need to find a different way of excluding the two first posts.

    Thread Starter Reed Gustow

    (@echofoxtrot)

    Hi, alchymyth. Thanks – that answers my question. Sorry to take so long to respond to your answer. Glad to know that it is not just some goof I made. I can probably do this by changing the categories on those.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘previous_posts_link and next_posts_link do not appear in custom query’ is closed to new replies.