WordPress.org

Support

Support » Plugins and Hacks » Display All But One Category

Display All But One Category

  • I have a three column layout, WP 2.1 running all the latest PHP and MySQL installs. On my right column I have code that displays the 10 most recent posts…

    <h1><?php _e("Recent Stories"); ?></h1>
      <?php
        $today = current_time('mysql', 1);
        if ( $recentposts = $wpdb->get_results
        ("SELECT ID, post_title FROM $wpdb->posts
        WHERE post_status = 'publish' AND
        post_type='post' ORDER BY post_date DESC
        LIMIT 10"));
      ?>
        <ul>
    
      <?php
        foreach ($recentposts as $post) {
        if ($post->post_title == '')
        $post->post_title = sprintf(__('Post #%s'), $post->ID);
    
        echo "<li><a href='".get_permalink($post->ID)."'>";
        the_title();
        echo '</a></li>';
        }
      ?>
        </ul>

    …and it works perfect. However, I also display category 5 in a list below that, and want to exclude it from the query above. How can I do this? I have tried LEFT JOIN with other tables but I just cannot seem to get this to work. I would rather it be exclusive (exclude one category) rather than inclusive (include everything else) because our site is pretty bug and I do not want to list out a comma separated list of all categories TO use, make sense? Any advice would be appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display All But One Category’ is closed to new replies.