Forums

[closed] 3 Loop System (3 posts)

  1. GeorgeOz
    Member
    Posted 1 year ago #

    Hi there, I am currently trying to get a 3 loop system working on my theme.

    I am getting a few problems.

    This is how I want it:

    Home Page:
    Loop 1
    - Featured post, 1 Post (from Featured Category only)

    Loop 2
    - Latest Posts, 4 Posts (All remaining posts except Featured and Resources cat)

    Loop 3
    - Latest Resources, 4 Posts (from Resources Category only)

    Here is my Loops:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    The problem I am getting is the 3rd loop is showing posts from the resources category BUT the 2nd loop is also showing the resources posts I need the 2nd post to not duplicate either 1st or 2nd loop.

    If that make sense? lol

    Hope someone can help, thanks.

    George

  2. vtxyzzy
    Member
    Posted 1 year ago #

    In the first 2 loops, add the ID of the current post to an array, something like this (UNTESTED):

    $seen = array(); // Put this before the first loop

    Use code like this to add the current post ID to the array:

    if (have_posts()) {
       while (have_posts()) {
          the_post();
          $seen[] = $post->ID;

    Then, in the third loop, add the post_not_in argument with the IDs:

    $args = array(
       'cat' = 44,  // the category id of Resources
       // add your other arguments here
    );
    $ids = implode(',',$seen);
    if ($ids) $args['post_not_in'] = $ids;
    query_posts($args);
  3. alchymyth
    The Sweeper
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic