• Resolved Anonymous User 5746546

    (@anonymized-5746546)


    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

Viewing 6 replies - 1 through 6 (of 6 total)
  • global $wp_query;
    query_posts(
    	array_merge(
    		array('cat' => -3),
    		$wp_query->query
    	)
    );
    Thread Starter Anonymous User 5746546

    (@anonymized-5746546)

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

    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.

    First line should be:

    $query_string = "posts_per_page=5&cat=-3";
    Thread Starter Anonymous User 5746546

    (@anonymized-5746546)

    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);
    }
    ?>
    Thread Starter Anonymous User 5746546

    (@anonymized-5746546)

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘excluding posts on main page’ is closed to new replies.