WordPress.org

Ready to get started?Download WordPress

Forums

problem getting pagination to work (6 posts)

  1. smrdo
    Member
    Posted 5 years ago #

    hi, I have and a page set up to dispaly a maximum of 5 post (set in the wordpress admin section)and only belonging to a certain category.
    There could be losts of these posts so id like to paginate between pages of posts belonging to this category, however clicking newer or older links the page just stay on the same initial set of 5 posts
    [code]
    <div id="newsListHolder">
    <div id="newsListBottom" class="clearfix">
    <ul id="newsGallery" class="clearfix">
    <?php
    query_posts("cat=4&orderby=modified"); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

  2. <?php the_content(); ?>
  3. <?php endwhile; ?>
    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    </div>

    </div>

    </div>
    <?php else : ?>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    [/code]
    Many thanks in advance

  • babyboy808
    Member
    Posted 5 years ago #

    Add this above your query_post:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>

    And this in your query:

    query_posts("cat=4&orderby=modified&&paged=$page");

  • smrdo
    Member
    Posted 5 years ago #

    thanks, tried that and nothing happened, the posts stayed the same, only the "newer" & "older" links changed as appropriate

  • smrdo
    Member
    Posted 5 years ago #

    I did mange to get it working using the following
    [code]
    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=5&cat=4&&orderby=modified'.'&paged='.$paged);
    ?>

    in place of
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 0; ?>
    <?php
    query_posts("cat=4&orderby=modified&&paged=$page&&&showposts=3"); ?>`

  • babyboy808
    Member
    Posted 5 years ago #

    Sorry, try: query_posts("cat=4&orderby=modified&paged=$paged");

  • smrdo
    Member
    Posted 5 years ago #

    thanks, that did it too

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags