• Hi! I’m trying to implement a magazine style theme. I’m using Mimbo 2.2 but have changed the “feature” section so that it now shows the latest post from an array of categories.

    Code is the rather banal <?php query_posts(‘showposts=1’); ?>
    In other areas in the same page I’m showing the latest article from each category.

    <?php $display_categories = array(5,6,7);
    foreach ($display_categories as $category) { ?>
    <div class=”clearfloat”> <?php query_posts(“showposts=1&cat=$category”);
    $wp_query->is_category = false;
    $wp_query->is_archive = false;
    $wp_query->is_home = true;
    ?>

    Now, is there any code I can use to exclude the latest post if it is already shown in the “feature” section so that it doesn’t get duplicated in the page? I was thinking of a code which says that if the post is the latest in general (not only within the category), then the 2nd latest post in the category should be shown…
    Thanks in advance for the help

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Save the category numbers from the first post displayed. Then, if you’re pulling for that category, add the offset=1 parameter to make it skip the first post.

    Thread Starter nanopausa

    (@nanopausa)

    Ok, now it will be evident I’m a true newbie to php and WP… how do I save the category numbers?
    Thanks again!!

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Well, in the first Loop, you could do something like this:

    $mycats = get_the_category();

    That will get the categories array and store it in $mycats.

    Then you need to look at all these categories and check if 5, 6, or 7 is one of them, yes? So first you get the ID’s out and put them in a new array:

    foreach($mycats as $mycat)
      $mycatids[] = $mycat->term_id;

    Next, you add a check for your categories into your foreach loop like so:

    <?php $display_categories = array(5,6,7);
    foreach ($display_categories as $category) { ?>
    <div class="clearfloat"> <?php
    if (in_array($category,$mycatids)) {
    query_posts("showposts=1&cat=$category&offset=1");
    } else {
    query_posts("showposts=1&cat=$category");
    }
    ...

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Excluding the latest post’ is closed to new replies.