WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] excluding posts on main page

[Resolved] excluding posts on main page

  • L D

    @enochfung

    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)
  • esmi

    @esmi

    Forum Moderator

    global $wp_query;
    query_posts(
    	array_merge(
    		array('cat' => -3),
    		$wp_query->query
    	)
    );
    L D

    @enochfung

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

    shawnyuan

    @shawnyuan

    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.
    shawnyuan

    @shawnyuan

    First line should be:

    $query_string = "posts_per_page=5&cat=-3";
    L D

    @enochfung

    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);
    }
    ?>
    L D

    @enochfung

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

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