WordPress.org

Support

Support » Plugins and Hacks » Hacks » Problems with old posts with this code

Problems with old posts with this code

  • I am using this code, to have posts in columns. With this code i can’t see pages with older posts. i can open page/2 but there is only the same posts i have in first page. do u know how to fix it, guys? 🙁

    <?php query_posts('showposts=5'); ?>
     <?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
     <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>
    <?php the_title(); ?>
     <?php the_content(); ?>
    <?php $count1++; } ?>
     <?php endforeach; ?>

    [Please post code or markup snippets between backticks or use the code button.]

Viewing 6 replies - 1 through 6 (of 6 total)
  • http://vudu.me/10f

    Check that out, you just need to account for pagination in your query.

    query_posts kills the original query, so pagination gets stomped. You can just put it back in!

    When i add this in the end, it is still not working:

    <?php query_posts( array(
          'posts_per_page' => 3,
          'cat' => '',
          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
     ));
    ?>

    [Please post code or markup snippets between backticks or use the code button.]

    I’m trying to figure out what you are doing exactly?

    In your top bit of code…. you use query_posts, and get_posts

    You wouldn’t need both.

    Also, you wouldn’t add all that code you just pasted at the end. You need to incorporate the paged parameter into your query.

    i have 3 columns. In first i have this:

    <?php query_posts(‘showposts=3’); ?>
    <?php $posts = get_posts(‘numberposts=5&offset=0’); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == “3”) { break; } else { ?>

    <div id=”post-<?php the_ID(); ?>” class=”post”>
    <div class=”postMeta”>
    <p class=”container”>
    <span class=”date”><?php the_time(‘M j, Y’) ?></span>
    <span class=”comments”><?php comments_popup_link(‘0’, ‘1’, ‘%’); ?></span>
    </p>
    </div>
    <h2>” title=”<?php the_title(); ?>”><?php the_title(); ?></h2>
    <div class=”entry”>
    <?php the_content(); ?>
    </div>

    <?php $count1++; } ?>
    <?php endforeach; ?>

    second:
    ————————

    <?php query_posts(‘showposts=3’); ?>
    <?php $posts = get_posts(‘numberposts=5&offset=3’); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count2 = 0; if ($count2 == “3”) { break; } else { ?>

    <div id=”post-<?php the_ID(); ?>” class=”post”>
    <div class=”postMeta”>
    <p class=”container”>
    <span class=”date”><?php the_time(‘M j, Y’) ?></span>
    <span class=”comments”><?php comments_popup_link(‘0’, ‘1’, ‘%’); ?></span>
    </p>
    </div>
    <h2>” title=”<?php the_title(); ?>”><?php the_title(); ?></h2>
    <?php the_content(); ?>
    </div>

    <?php $count2++; } ?>
    <?php endforeach; ?>

    and third:
    ——————-

    <?php query_posts(‘showposts=3’); ?>
    <?php $posts = get_posts(‘numberposts=5&offset=6’); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count3 = 0; if ($count3 == “3”) { break; } else { ?>

    <div id=”post-<?php the_ID(); ?>” class=”post”>
    <div class=”postMeta”>
    <p class=”container”>
    <span class=”date”><?php the_time(‘M j, Y’) ?></span>
    <span class=”comments”><?php comments_popup_link(‘0’, ‘1’, ‘%’); ?></span>
    </p>
    </div>
    <h2>” title=”<?php the_title(); ?>”><?php the_title(); ?></h2>
    <div class=”entry”>
    <?php the_content(); ?>
    </div>

    <?php $count3++; } ?>
    <?php endforeach; ?>

    so, i have 3 columns with 3 posts in each column. Can u please tell what and how i need to change to make older posts work?
    ———-

    hm. THis is so not my area of strength… first up though in your query, showposts is deprecated a long time ago. posts_per_page is current

    http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

    As for the query, maybe turning

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

    into

    <?php query_posts( array(
          'posts_per_page' => 3,
          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
     ));
    ?>

    would do it? (YOu said you put it at the end, that isn’t rightm you need to add it to your existing query which is what I did here)

    I’m not sure if that needs to happen on all your loops or what… like I said, not my area. Hopefully this can help you a little…. if not, I’ll have to hope someone else can jump in

    still not working. Thanks anyway, i ll try to find different way to split post in columns.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Problems with old posts with this code’ is closed to new replies.
Skip to toolbar