• Resolved markuskylberg

    (@markuskylberg)


    I want to have three sections on the same page with posts in them, where different posts should be depends on their status, like this:

    Section 1
    [the most recent published post]

    Section 2
    [all scheduled posts]

    Section 3
    [all published posts except the most recent post]

    Currently, im using this code (the post_status and numberposts are different in each section, for Section 3 I also added an ‘offset=1’ to exclude the most recent post):

    <?php query_posts('post_status=publish', 'numberposts=1', 'orderby=post_date', 'order=DESC'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>

    The problem is that the numberpost and offset isn’t working, it’s showing all of my published posts. Is there another code entirely that I should use or is there something wrong with what I’m using?

    Any help would be much appreciated! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Use this function before each query_posts():

    <?php wp_reset_query(); ?>

    Thread Starter markuskylberg

    (@markuskylberg)

    this:

    <?php wp_reset_query(); ?>
    <?php query_posts('post_status=publish', 'numberposts=1', 'orderby=post_date', 'order=DESC'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>

    didnt work :/

    Try this:

    <?php wp_reset_query(); ?>
    <?php query_posts(array("post_status" => "publish", "orderby" => "post_date", "order" => "DESC", "posts_per_page" => 1)); ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>

    This will show the latest one post you have.

    Thread Starter markuskylberg

    (@markuskylberg)

    I tried another code that worked!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Three sections of posts with different criteria on same page’ is closed to new replies.