WordPress.org

Ready to get started?Download WordPress

Forums

Can't get the posts_nav_link to appear with query_posts (6 posts)

  1. marc0047
    Member
    Posted 9 years ago #

    I am using query_posts to limit the number of posts on a page. However, the posts_nav_link doesn't appear to allow the user to turn the page to look at previous entries. This is the following code, am I doing this correctly?

    <?php query_posts('cat=3&showposts=4'); ?>

    <?php while (have_posts()) : the_post(); ?>

    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>
    <div class="postdate"><?php the_time('F jS, Y') ?> </div>
    <div class="entry">
    <?php the_content('Read the rest of this entry »'); ?>
    </div> <!-- entry -->
    <?php endwhile; ?>

    <?php posts_nav_link('separator','prelabel','nextlabel'); ?>

  2. skippy
    Member
    Posted 9 years ago #

    Does the posts_nav_link() tag work if you modify your query_posts() like this:

    <?php
    query_posts('cat=3&showposts=4&paged=1');
    ?>

  3. iand
    Member
    Posted 9 years ago #

    I ran into this yesterday, from the codex page on query posts:
    WordPress then ignores the other parameters it received via the URL (such as page number or category).
    Adding &paged=1 doesn't seem to help.

  4. Joshua Sigar
    Member
    Posted 9 years ago #

    The following plugin may solve the issue, then. Set what category to show with the plugin, set number of posts to display from admin panel.

    http://dev.wp-plugins.org/file/front-page-cats/trunk/front_page_cats.php

    You have to customize it to affect a Page, instead of frontpage.

  5. iand
    Member
    Posted 9 years ago #

    Maybe use get_posts instead?

    <?php
    $posts = get_posts('numberposts=4&offset=0&category=3');
    foreach ($posts as $post) :
    ?>
    Your loop contents here
    <?php endforeach; ?>
    <?php posts_nav_link('separator','prelabel','nextlabel'); ?>

  6. marc0047
    Member
    Posted 9 years ago #

    Doing the $posts as $post technique would have been really nice to use, but unfortunately it didn't work. The ouput were posts with just the titles (but also as links to the actual story), and the navigation still failed to show up. But that's still a good trick to know! Thanks!

    I'm also not keen on using the plugin because I'm creating these other pages by hand code as opposed to using WP's Pages.

    '&paged1' also unfortunately didn't work.

    More suggestions would be great!

Topic Closed

This topic has been closed to new replies.

About this Topic