• Resolved Jellelle

    (@jellelle)


    Hi all

    I cant figure it out:
    I want to show the last post on my index page. Doesn’t matter what category as long as it is not from the category ‘twitter’ (twitter is category íD ‘5’).
    How do I do that?

    <?php $cat_posts = new WP_Query('orderby=post_date'); ?>
    <?php if($cat_posts->have_posts()) : ?><?php while($cat_posts->have_posts()) : $cat_posts->the_post(); ?>
    <?php if(!in_category('5')) :  ?>
    ...title stuff
    <?php endwhile; ?>
    <?php endif; ?>

    I know that won’t work, but it’s the best I can do

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Jellelle

    (@jellelle)

    Damn, nobody? ??

    Couldn’t you just do something like this:

    <?php
    // Get posts excluding category id 5
    query_posts('cat=-5');
    
    // the Loop
    while (have_posts()) : the_post();
      // the content of the post
      the_content('Read the full post ?');
    endwhile;
    ?>

    Just to clarify that – I wasnt positive it would work, so I went and tested it out – just throw

    <?php query_posts('cat=-3'); ?>

    above your loop. Make sure you get the dash (minus sign?) in front of the 3 to specify that you’re excluding, not including that category.

    Thread Starter Jellelle

    (@jellelle)

    Oh. So easy! I could kiss you

    Solved!
    Cheers

    yes, but how to limit it to the last post ONLY, especially in multiple loops?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show last post within all categories, except 1 category’ is closed to new replies.