WordPress.org

Ready to get started?Download WordPress

Forums

How to don't display posts from a specific category (2 posts)

  1. RedPitbull
    Member
    Posted 1 year ago #

    O have a blog with some categories: bmw, skoda, seat, blog. I want that on my index page to appear all posts posted in bmw, skoda and seat but no and to post from blog.

    That is my code that display the posts on index:

    div id="content" style="width:710px;">
        <?php if (have_posts()) : ?>
    
        <?php while (have_posts()) : the_post(); ?>
  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try and adapt from:

    <?php if (have_posts()) : ?>

    to:

    <?php global $wp_query;
    $blog_cat = get_term_by( 'slug', 'blog', 'category');
    $args = array_merge( $wp_query->query_vars, array( 'category__not_in' => array( $blog_cat->term_id ) ) );
    query_posts( $args );
    if (have_posts()) : ?>

    http://codex.wordpress.org/Function_Reference/query_posts#Preserving_Existing_Query_Parameters
    http://codex.wordpress.org/Function_Reference/get_term_by

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.