WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] excluding posts on main page (7 posts)

  1. L D
    Member
    Posted 3 years ago #

    Hello, I'm trying to exclude a category of posts from the main page but the code doesn't seem to work.

    <?php    if ( is_home() ) {
                            query_posts($query_string . '&cat=-3');
                        }
                ?>
    
                <?php if (have_posts()) : ?>
                    <?php while (have_posts()) : the_post(); ?>... etc.

    I'm not sure what I'm doing wrong. :S

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    global $wp_query;
    query_posts(
    	array_merge(
    		array('cat' => -3),
    		$wp_query->query
    	)
    );
  3. L D
    Member
    Posted 3 years ago #

    Hello, I tried that and it didn't work. All the posts under category 3 still appear. :S

  4. shawnyuan
    Member
    Posted 3 years ago #

    Add the '&cat=-3' to the $query_string variable.

    For example;

    $query_string = "posts_per_page=5&cat=-3';
    query_posts($query_string); 
    
    }
    
    ?>
    
    <?php if (have_posts()) : ?>
                    <?php while (have_posts()) : the_post(); ?>... etc.
  5. shawnyuan
    Member
    Posted 3 years ago #

    First line should be:

    $query_string = "posts_per_page=5&cat=-3";
  6. L D
    Member
    Posted 3 years ago #

    Hello, it still doesn't work. :( I have this now...

    <?php
    
    $query_string = "posts_per_page=5&cat=-3";
    if ( is_home() ) {
       query_posts($query_string);
    }
    ?>
  7. L D
    Member
    Posted 3 years ago #

    Oh, nevermind, it works now. Thanks for all the help! :D

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.