WordPress.org

Ready to get started?Download WordPress

Forums

all except Latest from category in Loop (3 posts)

  1. Mistainu
    Member
    Posted 6 years ago #

    this may seem like an odd request, but i want to know how to call all posts except the latest one. i want to know how to do the following...

    loop search for latest post in category (example the featured category); then rewind loop; then search for all posts in all categories, except the latest post from a category (same as before, example noteworthy).

    why would i want to do this? well first i want the latest post from the featured category on top. then display all other posts (including the others from the featured category) below it. but i don't want the same post to appear at the top and among the other posts (it'll obviously look weird).

  2. Leads
    Member
    Posted 5 years ago #

    Hi.

    I would also like this.

    I want my home page to show the latest post and then underneath have a list of the next 4, 5, whatever posts.

    this comes close;

    <?php query_posts('showposts=5'); ?>
        <ul>
        <?php while (have_posts()) : the_post(); ?>
        <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
        <?php endwhile;?>
        </ul>

    But lists the latest post so it looks a bit funny.

    Thanks

  3. Leads
    Member
    Posted 5 years ago #

    AH! It's something called 'offset'

    This works!

    <ul id="recent-articles">
        <?php
        $temp = $wp_query;
        $wp_query= null;
        $wp_query = new WP_Query();
        $wp_query->query('showposts=3&offset=1'.'&paged='.$paged);
        ?>
        <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
          <li><a href="<?php the_permalink() ?>" rel="bookmark"><span><?php the_time('F j') ?></span> <?php the_title(); ?> </a></li>
        <?php endwhile; ?>
        </ul>
    
        <?php $wp_query = null; $wp_query = $temp;?>

Topic Closed

This topic has been closed to new replies.

About this Topic