• Hey there, I would like to use the admin panel setting to show a certain number of posts on my blog say 5, but then I would like to do a query posts after that initial loop and show a list of the previous 5 posts (post id and title permalink only). I want it to be category independent, meaning it doesnt matter what category the posts are in, just show the next 5 in chronological order.

    *and as an alternate, is there a way to show the next 5 as a random list also?

    the one I’ve got now shows 5 posts but it shows the same 5 posts as the initial loop (I have 5 set in wp admin to show)

    <ul id="previously">
    <?php query_posts('showposts=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li><?php the_ID(); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"></a></li>
    <?php endwhile; ?>
    </ul>

    thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Just a tip: if you only want to show id and permalink, use the much easier get_posts.

    Thread Starter lokjah

    (@lokjah)

    ah cool, so would I do something like:

    $posts = get_posts('numberposts=5&offset=5);
    foreach($posts as $post) :
    ?>

    to show the previous 5 after the first loop of 5?

    Thread Starter lokjah

    (@lokjah)

    sweet that worked dope! thanks firas….

    now how about getting that previous 5 as random titles?

    Try doing shuffle($posts); right before the foreach loop?

    Thread Starter lokjah

    (@lokjah)

    hmmm close firas

    that seems to shuffle the order of the outputted post list, what I really wanted was it to pull random posts from all my posts..

    this shuffle is cool tho..

    maybe there isnt enough parameters in the get_posts to do this and I might need to go back to a second loop?

    Thread Starter lokjah

    (@lokjah)

    ah one more thing.. im getting the same post id for each of those titles, and its actually the same post id as the last one in the first loop..

    eg, the last post in my blog (#5) is post id 88, the code I’m using below shows each of these next 5 as post id 88 also, the titles work fine but not the id..

    <ul id="previous">
    <?php
    $posts = get_posts('numberposts=5&offset=5');
    //shuffle($posts); shuffles order of output posts
    foreach($posts as $post) :
    ?>
    <li><?php the_ID(); ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </li>
    <?php endforeach; ?>
    </ul>

    in action_

    https://clintfisherart.com/news/

    Thread Starter lokjah

    (@lokjah)

    argh.. helps if I read…

    setup_postdata($post);

    thats sussed… ??

    just need to know how to do the random one now so it grabs 5 from all my posts available, rather than the 5 in the offset…

    any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Query Posts-previous five posts how?’ is closed to new replies.