WordPress.org

Support

Support » Plugins and Hacks » Hacks » How to offset posts in one category by 3 in main page's loop?

How to offset posts in one category by 3 in main page's loop?

  • William

    @daniel_ac

    I have a “featured” section on the main page which highlights selected blog posts, and this section sits right above the main blog loop. How do I edit the following code to exclude the three latest posts in category id 7 (category name is “Featured”) from displaying in the main blog loop?

    The code below is from my theme’s index page; I have a hunch this is where the change would need to be made, but my searches haven’t turned up anything that deals with this specific bit of code.

    <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>

    If I’m wrong, let me know! Thank you in advance for your help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael

    @alchymyth

    not directly what you are asking for, but a possible way to achieve what you want;
    check the methods for ‘do-not-duplicate’ in this docu:
    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

    William

    @daniel_ac

    Hmm… Thanks alchymyth. To be honest, this doesn’t look very familiar to me. Would this really achieve what I’m looking for, but in a round-about way?

    I’m open to any other suggestions. I’ve got a feeling the solution is probably a simple one (slight modification of existing code?).

    Inside your featured posts loop store the IDs of each post inside an array, then in your the main loop use that array to exclude those posts from the main query..

    Before your featured posts loop..

    <?php $featured_ids = array(); ?>

    Inside the featured loop..

    <?php $featured_ids[] = get_the_ID(); ?>

    Before your main query/loop(what you posted above)..

    <?php query_posts( array_merge( array( 'post__not_in' => $featured_ids ), $wp_query->query ) ); ?>

    I don’t think you’ll make it any more simple than that… so i hope that helps..

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to offset posts in one category by 3 in main page's loop?’ is closed to new replies.
Skip to toolbar