• Zambrano Sergio

    (@sergiozambrano)


    How can I skip posts whose main category has already been taken for some previous post in the loop?

    The idea is to show only 1 post from each category, and skip the rest. It’s ok to match the first category assigned to the each post only.

    E.g.

    loaded = new array;
    for (i=0 : post-loop-begins-here)
    if (post.catID == loaded[try all instances]) {
    loaded[i]=”post.catID”;
    next post
    } else {
    the_content();
    }
    end for

    That way you get a “first post for each category” loop without the complex code is usually proposed – like this

Viewing 4 replies - 1 through 4 (of 4 total)
  • MichaelH

    (@michaelh)

    Guess you need to use get_the_category and test the first value of that array.

    Thread Starter Zambrano Sergio

    (@sergiozambrano)

    Yep, that’s what I guessed.
    But how do I test the next posts against all of the ones saved in “loaded” array?
    My php language is limited to reading, no writing… although I’m definitively learning basics by copy/paste and help in forums 🙂

    Thread Starter Zambrano Sergio

    (@sergiozambrano)

    I’m a little closer to an actual code…
    I just need to figure out how to compare get_the_category to all the values inside “loaded”, or how to extend in_category to all the values in “counting”

    <?php
    loaded = new array;
    var counting = 0;
    while (have_posts()): the_post();
    if ( in_category(counting[all of them]) ) {
    counting++;
    continue;
    } else {
    the_content();
    }
    end while;
    ?>

    Thread Starter Zambrano Sergio

    (@sergiozambrano)

    Unfortunatelly, it’s not a real php code.

    Any help to make it real?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Skipping posts from none-of-these[n] categories?’ is closed to new replies.