WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Display All But One Category (3 posts)

  1. thebindlestick
    Member
    Posted 7 years ago #

    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.

  2. moshu
    Member
    Posted 7 years ago #

    Slow down and keep it in one single topic!
    How many times will you ask thje same question in different new topics?
    http://wordpress.org/support/topic/121123?replies=2
    http://wordpress.org/support/topic/121203?replies=3

  3. Firas
    Member
    Posted 7 years ago #

    If you're familiar with LEFT JOIN... you need to cross reference the post_ID with the one in post2cat

Topic Closed

This topic has been closed to new replies.

About this Topic